Last active
July 26, 2016 01:17
-
-
Save Havvy/684e357bf9276507ad82f8b6d7e30dd7 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
// I'm not sure how much the Copy bound is actually necessary... | |
trait LeftRight<T: Copy> { | |
left: T, | |
right: T | |
} | |
impl<C: Copy, LR: LeftRight<C>, T: LR> T { | |
fn swap(&mut self) { | |
let temp = self.right; | |
self.right = self.left; | |
self.left = temp; | |
} | |
} | |
#[impl(Debug, Clone, Copy)] | |
struct IntPair(i32, i32); | |
impl LeftRight<i32> for IntPair { | |
left = self.0, | |
right = self.1 | |
} | |
fn main () { | |
let mut numbers = IntPair(0i32, 1i32); | |
numbers.swap(); | |
println!("{:?}", numbers); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment