Created
February 9, 2021 23:12
-
-
Save adetaylor/e45d44ad58263bab4194e8e0e2093553 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
```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