Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created March 20, 2019 02:41
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 rust-play/92fa096554c2282b9ebcb7346840c70a to your computer and use it in GitHub Desktop.
Save rust-play/92fa096554c2282b9ebcb7346840c70a to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
use std::ops::Sub;
struct Foo {
value: i32
}
trait MuhTrait {
fn traitfn(self, other: Self) -> Self;
}
impl MuhTrait for Foo {
fn traitfn(self, other: Self) -> Self {
other.value - self.value
}
}
impl<T> Sub<T> for T where T: MuhTrait {
fn sub(self, other: T) -> T {
other.traitfn(self)
}
}
fn main() {
println!("Hello, world!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment