Skip to content

Instantly share code, notes, and snippets.

Created January 29, 2017 02:57
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 anonymous/6ab831eb38b1586bf51ee271bede2e30 to your computer and use it in GitHub Desktop.
Save anonymous/6ab831eb38b1586bf51ee271bede2e30 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
#[derive(Debug)]
struct Response<T> {
foo: String,
bar: String,
unknown: T
}
enum Action {
One,
Two(u8),
Three(String)
}
fn one() -> String {
String::from("foo")
}
fn two(x: u8) -> u8 {
x
}
fn three(s: String) -> i32 {
42
}
fn do_something<T>(action: Action) -> Response<T> {
Response {
foo: String::from("foo"),
bar: String::from("bar"),
unknown: match action {
Action::One => one(),
Action::Two(x) => two(x),
Action::Three(s) => three(s),
}
}
}
fn main() {
let res = do_something(Action::Two(42));
print!("{:?}", res)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment