blob: 8227f88f981317a6ac5a8cf7590eb570fd831ebe (
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#![allow(dead_code, unused_imports)]
#[macro_use]
extern crate derive_more;
#[derive(Deref)]
#[deref(forward)]
struct MyBoxedInt(Box<i32>);
#[derive(Deref)]
#[deref(forward)]
struct NumRef<'a> {
num: &'a i32,
}
#[derive(Deref)]
struct NumRef2<'a> {
#[deref(forward)]
num: &'a i32,
useless: bool,
}
#[derive(Deref)]
#[deref(forward)]
struct NumRef3<'a> {
num: &'a i32,
#[deref(ignore)]
useless: bool,
}
#[derive(Deref)]
struct MyInt(i32);
#[derive(Deref)]
struct Point1D {
x: i32,
}
#[derive(Deref)]
struct Point1D2 {
x: i32,
#[deref(ignore)]
useless: bool,
}
#[derive(Deref)]
struct CoolVec {
cool: bool,
#[deref]
vec: Vec<i32>,
}
#[derive(Deref)]
struct GenericVec<T>(Vec<T>);
#[test]
fn deref_generic() {
let gv = GenericVec(Vec::<i32>::new());
assert!(gv.is_empty())
}
#[derive(Deref)]
struct GenericBox<T>(#[deref(forward)] Box<T>);
#[test]
fn deref_generic_forward() {
let boxed = GenericBox(Box::new(1i32));
assert_eq!(*boxed, 1i32);
}
|