Last active
October 13, 2018 00:21
-
-
Save JuanCaicedo/fa33ec618c68560e4c39a15d2cfd03a0 to your computer and use it in GitHub Desktop.
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
struct Action { | |
_type: String, | |
amount: u32 | |
} | |
fn update_counter(state:u32, action: Action) { | |
let Action {_type, amount} = action; | |
return match _type.as_ref() { | |
"INCREMENT" => state + amount, | |
"DECREMENT" => state - amount, | |
"RESET" => 0, | |
_ => state | |
} | |
} | |
fn main() { | |
let newState = update_counter(4, Action { | |
_type: "INCREMENT", | |
amount: 2 | |
}); | |
println!("{}", newState); // 6 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment