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
#[macro_use]
extern crate getset;
#[derive(CopyGetters, Setters, WithSetters)]
#[getset(get_copy, set, set_with)]
pub struct Plain {
// If the field was not skipped, the compiler would complain about moving a
// non-copyable type.
#[getset(skip)]
non_copyable: String,
copyable: usize,
// Invalid use of skip -- compilation error.
// #[getset(skip, get_copy)]
// non_copyable2: String,
// Invalid use of skip -- compilation error.
// #[getset(get_copy, skip)]
// non_copyable2: String,
}
impl Plain {
fn custom_non_copyable(&self) -> &str {
&self.non_copyable
}
// If the field was not skipped, the compiler would complain about duplicate
// definitions of `set_non_copyable`.
fn set_non_copyable(&mut self, val: String) -> &mut Self {
self.non_copyable = val;
self
}
// If the field was not skipped, the compiler would complain about duplicate
// definitions of `with_non_copyable`.
fn with_non_copyable(mut self, val: String) -> Self {
self.non_copyable = val;
self
}
}
impl Default for Plain {
fn default() -> Self {
Plain {
non_copyable: "foo".to_string(),
copyable: 3,
}
}
}
#[test]
fn test_plain() {
let mut val = Plain::default();
val.copyable();
val.custom_non_copyable();
val.set_non_copyable("bar".to_string());
val = val.with_non_copyable("foo".to_string());
let _ = val;
}