/
githubmirror
/
sway
Обзор
Документация
Войти
/
githubmirror
/
sway
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/match_expressions/src/main.sw
53 строки
1 KB
Igor Rončević
Struct field privacy (#5508)
30 янв 2024, 16:15
Не верифицирован
30 янв 2024, 16:15
8320c1b
Код
Авторство
О чём код?
script; // helper functions for our example fn on_even(num: u64) { // do something with even numbers } fn on_odd(num: u64) { // do something with odd numbers } fn main(num: u64) -> u64 { // Match as an expression let is_even = match num % 2 { 0 => true, _ => false, }; // Match as control flow let x = 12; match x { 5 => on_odd(x), _ => on_even(x), }; // Match an enum enum Weather { Sunny: (), Rainy: (), Cloudy: (), Snowy: (), } let current_weather = Weather::Sunny; let avg_temp = match current_weather { Weather::Sunny => 80, Weather::Rainy => 50, Weather::Cloudy => 60, Weather::Snowy => 20, }; let is_sunny = match current_weather { Weather::Sunny => true, Weather::Rainy | Weather::Cloudy | Weather::Snowy => false, }; // match expression used for a return let outside_temp = Weather::Sunny; match outside_temp { Weather::Sunny => 80, Weather::Rainy => 50, Weather::Cloudy => 60, Weather::Snowy => 20, } }