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
trait Foo {
fn foo(&self);
}
trait Bar {
fn bar(&self);
}
impl Foo for u32 {
fn foo(&self) {
println!("u32::foo");
}
}
impl Bar for u32 {
fn bar(&self) {
println!("u32::bar");
}
}
impl Foo for String {
fn foo(&self) {
println!("String::foo");
}
}
fn call_foo<T>(value: T)
where T: Foo
{
value.foo()
}
//fn call_bar<T: Foo>(value: T) { value.bar() }
//fn call_bar(value: Foo) { value.bar() } // not ok
//fn call_bar(value: impl Foo) { value.bar() }
fn main() {
(1u32).bar();
call_foo(1u32);
call_foo("foo".to_string());
}