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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#[fieldwork(get, set, get_mut, with)]
struct User {
/// whether this user is an admin
///
/// Note that this is distinct from the notion of group administration,
/// for historical reasons
#[fieldwork(argument = is_admin, get = is_admin, get_mut = is_admin_mut)]
admin: bool,
/// the user's name
name: String,
/// the user's favorite color, if set
favorite_color: Option<String>,
#[fieldwork(skip)]
private: (),
/// read-only unique identifier
#[fieldwork(opt_in, get)]
id: Vec<u8>,
}
impl User {
/**Returns a copy of whether this user is an admin
Note that this is distinct from the notion of group administration,
for historical reasons*/
pub fn is_admin(&self) -> bool {
self.admin
}
/**Mutably borrow whether this user is an admin
Note that this is distinct from the notion of group administration,
for historical reasons*/
pub fn is_admin_mut(&mut self) -> &mut bool {
&mut self.admin
}
/**Sets whether this user is an admin, returning `&mut Self` for chaining
Note that this is distinct from the notion of group administration,
for historical reasons*/
pub fn set_admin(&mut self, is_admin: bool) -> &mut Self {
self.admin = is_admin;
self
}
/**Owned chainable setter for whether this user is an admin, returning `Self`
Note that this is distinct from the notion of group administration,
for historical reasons*/
#[must_use]
pub fn with_admin(mut self, is_admin: bool) -> Self {
self.admin = is_admin;
self
}
///Borrows the user's name
pub fn name(&self) -> &str {
&*self.name
}
///Mutably borrow the user's name
pub fn name_mut(&mut self) -> &mut str {
&mut *self.name
}
///Sets the user's name, returning `&mut Self` for chaining
pub fn set_name(&mut self, name: String) -> &mut Self {
self.name = name;
self
}
///Owned chainable setter for the user's name, returning `Self`
#[must_use]
pub fn with_name(mut self, name: String) -> Self {
self.name = name;
self
}
///Borrows the user's favorite color, if set
pub fn favorite_color(&self) -> Option<&str> {
self.favorite_color.as_deref()
}
///Mutably borrow the user's favorite color, if set
pub fn favorite_color_mut(&mut self) -> Option<&mut str> {
self.favorite_color.as_deref_mut()
}
///Sets the user's favorite color, if set, returning `&mut Self` for chaining
pub fn set_favorite_color(&mut self, favorite_color: Option<String>) -> &mut Self {
self.favorite_color = favorite_color;
self
}
///Owned chainable setter for the user's favorite color, if set, returning `Self`
#[must_use]
pub fn with_favorite_color(mut self, favorite_color: Option<String>) -> Self {
self.favorite_color = favorite_color;
self
}
///Borrows read-only unique identifier
pub fn id(&self) -> &[u8] {
&*self.id
}
}