Skip to content

Instantly share code, notes, and snippets.

@quake
Created February 9, 2018 09:35
Show Gist options
  • Save quake/2522fdc570efebe69289776c82d51310 to your computer and use it in GitHub Desktop.
Save quake/2522fdc570efebe69289776c82d51310 to your computer and use it in GitHub Desktop.
struct ContainerFoo(i32, i32);
struct ContainerBar(i64, i64);
trait Contains {
type A;
type B;
fn contains(&self, &Self::A, &Self::B) -> bool;
}
impl Contains for ContainerFoo {
type A = i32;
type B = i32;
fn contains(&self, number_1: &i32, number_2: &i32) -> bool {
(&self.0 == number_1) && (&self.1 == number_2)
}
}
impl Contains for ContainerBar {
type A = i64;
type B = i64;
fn contains(&self, number_1: &i64, number_2: &i64) -> bool {
(&self.0 == number_1) && (&self.1 == number_2)
}
}
struct FooBar<'a, Ta: 'a, Tb: 'a> {
pub container: &'a Contains<A=Ta, B=Tb>,
}
fn main() {
let number_1 = 3;
let number_2 = 10;
let foobar = FooBar {
container: &ContainerFoo(number_1, number_2),
};
println!("Does container contain {} and {}: {}",
&number_1, &number_2,
foobar.container.contains(&number_1, &number_2));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment