forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
match expressions take 2 (FuelLabs#1355)
* match expressions take 2 * fix directory * match statements * formatting editor fix * fmt Co-authored-by: SilentCicero <> Co-authored-by: Mohammad Fawaz <[email protected]>
- Loading branch information
1 parent
c158ef7
commit 0bfaa66
Showing
4 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[[package]] | ||
name = 'core' | ||
dependencies = [] | ||
|
||
[[package]] | ||
name = 'match_statements' | ||
dependencies = ['std'] | ||
|
||
[[package]] | ||
name = 'std' | ||
dependencies = ['core'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "match_statements" | ||
|
||
[dependencies] | ||
std = { path = "../../sway-lib-std" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
script; | ||
|
||
fn foo() { | ||
// do something | ||
} | ||
fn bar() { | ||
// do something | ||
} | ||
|
||
fn main() -> u64 { | ||
let x = 5; | ||
|
||
// Match as an expression. | ||
let a = match 8 { | ||
7 => { | ||
4 | ||
}, | ||
9 => { | ||
5 | ||
}, | ||
8 => { | ||
6 | ||
}, | ||
_ => { | ||
100 | ||
}, | ||
}; | ||
|
||
// Match as a statement for control flow. | ||
match x { | ||
5 => { | ||
foo() | ||
}, | ||
_ => { | ||
bar() | ||
}, | ||
}; | ||
|
||
// Match as expression used for a return. | ||
match 42 { | ||
0 => { | ||
24 | ||
}, | ||
foo => { | ||
foo | ||
}, | ||
} | ||
} |