Created
January 6, 2017 16:21
-
-
Save matematikaadit/2af6324d19f3e467c1e1016f882247dc to your computer and use it in GitHub Desktop.
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 Next<S> { | |
fn next(&mut self) -> S; | |
} | |
#[derive(Debug)] | |
struct Multi { | |
s: &'static str, | |
n: u8, | |
x: f32, | |
} | |
impl Next<&'static str> for Multi { | |
fn next(&mut self) -> &'static str { | |
self.s | |
} | |
} | |
impl Next<u8> for Multi { | |
fn next(&mut self) -> u8 { | |
self.n | |
} | |
} | |
impl Next<f32> for Multi { | |
fn next(&mut self) -> f32 { | |
self.x | |
} | |
} | |
fn main() { | |
let mut multi = Multi { s: "Hello, World!", n: 42, x: 0.3 }; | |
println!("{:?}", multi); | |
let n: u8 = multi.next(); | |
println!("{:?}", n); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment