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
//! Default methods and lifetime elision in return types.
use auto_tuple::auto_tuple;
#[auto_tuple]
trait Tr {
fn base(&self) -> usize;
fn derived(&self) -> usize {
self.base() + 100
}
fn name(&self) -> &str;
}
struct X;
struct Y;
impl Tr for X {
fn base(&self) -> usize {
1
}
fn name(&self) -> &str {
"x"
}
}
impl Tr for Y {
fn base(&self) -> usize {
2
}
fn name(&self) -> &str {
"y"
}
}
fn main() {
let t = (X, Y);
// Default body is inherited through the element's own default impl.
assert_eq!(t.derived(), (101, 102));
// Elided lifetimes in `&str` returns tupleize fine.
assert_eq!(t.name(), ("x", "y"));
}