Skip to content

Instantly share code, notes, and snippets.

@richo
Created November 17, 2020 04:09
Show Gist options
  • Save richo/1f9ea71ec76146bb9f8e31e7ca20dd32 to your computer and use it in GitHub Desktop.
Save richo/1f9ea71ec76146bb9f8e31e7ca20dd32 to your computer and use it in GitHub Desktop.
pub enum Thing {
Lol {
name: String,
other: u64,
},
Haha {
name: String,
whatever: i8,
}
}
impl Thing {
fn with_modification(&self) -> Thing {
use Thing::*;
let tweak = "hahahahaha";
match self {
lol @ Lol { .. } => {
let new = lol.clone();
new.name.push_str(tweak);
new
},
haha @ Haha { .. } => {
let new = haha.clone();
new.name.push_str(tweak);
new
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment