blob: af5f5a6fab40311dbbd706c13a4af2192dea1232 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
// Testing multiple supertraits and calling supertrait methods
struct Foo {
my_int: u32,
}
trait GrandParent {
fn grandparent(&self) -> u32;
}
trait Parent : GrandParent {
fn parent(&self) -> bool;
}
trait Child : Parent {
fn child(&self);
}
impl GrandParent for Foo {
fn grandparent(&self) -> u32 {
self.my_int
}
}
impl Parent for Foo {
fn parent(&self) -> bool {
// Call supertrait method
return self.grandparent() != 0;
}
}
impl Child for Foo {
fn child(&self) {
let _ = self;
}
}
pub fn main() {
let a = Foo{my_int: 0xfeedf00d};
let b: &dyn Child = &a;
b.parent();
b.child();
// Here to silence bogus compiler warning
let _ = a.my_int;
}
|