Skip to content

Instantly share code, notes, and snippets.

@JuanCaicedo
Created October 13, 2018 00:10
Show Gist options
  • Save JuanCaicedo/d9e3e9908a3591dbdae8772767a4dd69 to your computer and use it in GitHub Desktop.
Save JuanCaicedo/d9e3e9908a3591dbdae8772767a4dd69 to your computer and use it in GitHub Desktop.
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
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment