Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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));
- }
Add Comment
Please, Sign In to add comment