Skip to content

Instantly share code, notes, and snippets.

@raindev
Created May 30, 2018 07:00
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 raindev/bbc0b183c18d001e40b987c4bd846de4 to your computer and use it in GitHub Desktop.
Save raindev/bbc0b183c18d001e40b987c4bd846de4 to your computer and use it in GitHub Desktop.
Rust generic constraints
trait Wrap {
fn pass<F>(&self, consumer: F) where F: Fn(&Self) {
consumer(self)
}
}
struct Stringy(String);
impl Wrap for Stringy {
}
fn main() {
let print_stringy = |x: &Stringy| {
match x {
Stringy(s) => println!("{}", s)
}
};
print_stringy(&Stringy("hello world".to_string()))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment