Skip to content

Instantly share code, notes, and snippets.

@Havvy
Last active July 26, 2016 01:17
Show Gist options
  • Save Havvy/684e357bf9276507ad82f8b6d7e30dd7 to your computer and use it in GitHub Desktop.
Save Havvy/684e357bf9276507ad82f8b6d7e30dd7 to your computer and use it in GitHub Desktop.
// 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