Created
May 30, 2018 07:00
-
-
Save raindev/bbc0b183c18d001e40b987c4bd846de4 to your computer and use it in GitHub Desktop.
Rust generic constraints
This file contains hidden or 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
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