Created
February 9, 2018 09:35
-
-
Save quake/2522fdc570efebe69289776c82d51310 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
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