1macro_rules! impl_get_set {
4 ($ty_name:ident, $name:ident, $with:ident, $without:ident $(, $extra_doc:literal)? $(,)?) => {
5 #[doc = concat!("Returns the value of the \"", stringify!($name), "\" refresh kind.")]
6 $(#[doc = concat!("
7", $extra_doc, "
8")])?
9 #[doc = concat!("
10```
11use sysinfo::", stringify!($ty_name), ";
12
13let r = ", stringify!($ty_name), "::nothing();
14
15let r = r.with_", stringify!($name), "();
16assert_eq!(r.", stringify!($name), "(), true);
17
18let r = r.without_", stringify!($name), "();
19assert_eq!(r.", stringify!($name), "(), false);
20```")]
21 pub fn $name(&self) -> bool {
22 self.$name
23 }
24
25 #[doc = concat!("Sets the value of the \"", stringify!($name), "\" refresh kind to `true`.
26
27```
28use sysinfo::", stringify!($ty_name), ";
29
30let r = ", stringify!($ty_name), "::nothing();
31
32let r = r.with_", stringify!($name), "();
33assert_eq!(r.", stringify!($name), "(), true);
34```")]
35 #[must_use]
36 pub fn $with(mut self) -> Self {
37 self.$name = true;
38 self
39 }
40
41 #[doc = concat!("Sets the value of the \"", stringify!($name), "\" refresh kind to `false`.
42
43```
44use sysinfo::", stringify!($ty_name), ";
45
46let r = ", stringify!($ty_name), "::everything();
47assert_eq!(r.", stringify!($name), "(), true);
48
49let r = r.without_", stringify!($name), "();
50assert_eq!(r.", stringify!($name), "(), false);
51```")]
52 #[must_use]
53 pub fn $without(mut self) -> Self {
54 self.$name = false;
55 self
56 }
57 };
58
59 ($ty_name:ident, $name:ident, $with:ident, $without:ident, UpdateKind $(, $extra_doc:literal)? $(,)?) => {
61 #[doc = concat!("Returns the value of the \"", stringify!($name), "\" refresh kind.")]
62 $(#[doc = concat!("
63", $extra_doc, "
64")])?
65 #[doc = concat!("
66```
67use sysinfo::{", stringify!($ty_name), ", UpdateKind};
68
69let r = ", stringify!($ty_name), "::nothing();
70assert_eq!(r.", stringify!($name), "(), UpdateKind::Never);
71
72let r = r.with_", stringify!($name), "(UpdateKind::OnlyIfNotSet);
73assert_eq!(r.", stringify!($name), "(), UpdateKind::OnlyIfNotSet);
74
75let r = r.without_", stringify!($name), "();
76assert_eq!(r.", stringify!($name), "(), UpdateKind::Never);
77```")]
78 pub fn $name(&self) -> UpdateKind {
79 self.$name
80 }
81
82 #[doc = concat!("Sets the value of the \"", stringify!($name), "\" refresh kind.
83
84```
85use sysinfo::{", stringify!($ty_name), ", UpdateKind};
86
87let r = ", stringify!($ty_name), "::nothing();
88assert_eq!(r.", stringify!($name), "(), UpdateKind::Never);
89
90let r = r.with_", stringify!($name), "(UpdateKind::OnlyIfNotSet);
91assert_eq!(r.", stringify!($name), "(), UpdateKind::OnlyIfNotSet);
92```")]
93 #[must_use]
94 pub fn $with(mut self, kind: UpdateKind) -> Self {
95 self.$name = kind;
96 self
97 }
98
99 #[doc = concat!("Sets the value of the \"", stringify!($name), "\" refresh kind to `UpdateKind::Never`.
100
101```
102use sysinfo::{", stringify!($ty_name), ", UpdateKind};
103
104let r = ", stringify!($ty_name), "::everything();
105assert_eq!(r.", stringify!($name), "(), UpdateKind::OnlyIfNotSet);
106
107let r = r.without_", stringify!($name), "();
108assert_eq!(r.", stringify!($name), "(), UpdateKind::Never);
109```")]
110 #[must_use]
111 pub fn $without(mut self) -> Self {
112 self.$name = UpdateKind::Never;
113 self
114 }
115 };
116
117 ($ty_name:ident, $name:ident, $with:ident, $without:ident, $typ:ty $(,)?) => {
119 #[doc = concat!("Returns the value of the \"", stringify!($name), "\" refresh kind.
120
121```
122use sysinfo::{", stringify!($ty_name), ", ", stringify!($typ), "};
123
124let r = ", stringify!($ty_name), "::nothing();
125assert_eq!(r.", stringify!($name), "().is_some(), false);
126
127let r = r.with_", stringify!($name), "(", stringify!($typ), "::everything());
128assert_eq!(r.", stringify!($name), "().is_some(), true);
129
130let r = r.without_", stringify!($name), "();
131assert_eq!(r.", stringify!($name), "().is_some(), false);
132```")]
133 pub fn $name(&self) -> Option<$typ> {
134 self.$name
135 }
136
137 #[doc = concat!("Sets the value of the \"", stringify!($name), "\" refresh kind to `Some(...)`.
138
139```
140use sysinfo::{", stringify!($ty_name), ", ", stringify!($typ), "};
141
142let r = ", stringify!($ty_name), "::nothing();
143assert_eq!(r.", stringify!($name), "().is_some(), false);
144
145let r = r.with_", stringify!($name), "(", stringify!($typ), "::everything());
146assert_eq!(r.", stringify!($name), "().is_some(), true);
147```")]
148 #[must_use]
149 pub fn $with(mut self, kind: $typ) -> Self {
150 self.$name = Some(kind);
151 self
152 }
153
154 #[doc = concat!("Sets the value of the \"", stringify!($name), "\" refresh kind to `None`.
155
156```
157use sysinfo::", stringify!($ty_name), ";
158
159let r = ", stringify!($ty_name), "::everything();
160assert_eq!(r.", stringify!($name), "().is_some(), true);
161
162let r = r.without_", stringify!($name), "();
163assert_eq!(r.", stringify!($name), "().is_some(), false);
164```")]
165 #[must_use]
166 pub fn $without(mut self) -> Self {
167 self.$name = None;
168 self
169 }
170 };
171}
172
173pub(crate) use impl_get_set;