Skip to content

Instantly share code, notes, and snippets.

@JuanCaicedo
Created October 13, 2018 00:03
Show Gist options
  • Save JuanCaicedo/ac39c994c7979445132d24de142a786c to your computer and use it in GitHub Desktop.
Save JuanCaicedo/ac39c994c7979445132d24de142a786c to your computer and use it in GitHub Desktop.
struct Action {
_type: String,
amount: u32
}
fn update_counter(state:32, action: Action) {
let Action {_type, amount} = action;
return match _type.as_ref() {
"INCREMENT" => state + amount,
"DECREMENT" => state - amount,
"RESET" => 0,
_ => state
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment