Skip to content

Instantly share code, notes, and snippets.

@adetaylor
Created February 9, 2021 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adetaylor/e45d44ad58263bab4194e8e0e2093553 to your computer and use it in GitHub Desktop.
Save adetaylor/e45d44ad58263bab4194e8e0e2093553 to your computer and use it in GitHub Desktop.
```rust
enum Thing<D> {
AnItem(i32),
C(D),
}
type A = Thing<()>;
type B = Thing<String>;
fn demo() {
let items = vec![
Thing::AnItem(32),
Thing::C(()),
];
let more_complicated_items: Vec<_> = items.into_iter().map(fill_in_payload).collect();
}
fn fill_in_payload(thing: A) -> B {
match thing {
Thing::AnItem(a) => Thing::AnItem(a), // can I avoid this line?
// If there are lots of other variants in Thing it's tedious
Thing::C(_) => Thing::C("payload".into())
}
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment