Skip to content

Commit 7b70c66

Browse files
committed
clippy::or_fun_call
1 parent 9d0a348 commit 7b70c66

10 files changed

Lines changed: 154 additions & 115 deletions

File tree

crates/stackable-operator/src/builder/meta.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl ObjectMetaBuilder {
106106
/// It'll override an annotation with the same key.
107107
pub fn with_annotation(&mut self, annotation: Annotation) -> &mut Self {
108108
self.annotations
109-
.get_or_insert(Annotations::new())
109+
.get_or_insert_with(Annotations::new)
110110
.insert(annotation);
111111
self
112112
}
@@ -115,7 +115,7 @@ impl ObjectMetaBuilder {
115115
/// Any existing annotation with a key that is contained in `annotations` will be overwritten
116116
pub fn with_annotations(&mut self, annotations: Annotations) -> &mut Self {
117117
self.annotations
118-
.get_or_insert(Annotations::new())
118+
.get_or_insert_with(Annotations::new)
119119
.extend(annotations);
120120
self
121121
}
@@ -129,14 +129,14 @@ impl ObjectMetaBuilder {
129129
/// This adds a single label to the existing labels.
130130
/// It'll override a label with the same key.
131131
pub fn with_label(&mut self, label: Label) -> &mut Self {
132-
self.labels.get_or_insert(Labels::new()).insert(label);
132+
self.labels.get_or_insert_with(Labels::new).insert(label);
133133
self
134134
}
135135

136136
/// This adds multiple labels to the existing labels.
137137
/// Any existing label with a key that is contained in `labels` will be overwritten
138138
pub fn with_labels(&mut self, labels: Labels) -> &mut Self {
139-
self.labels.get_or_insert(Labels::new()).extend(labels);
139+
self.labels.get_or_insert_with(Labels::new).extend(labels);
140140
self
141141
}
142142

@@ -158,7 +158,7 @@ impl ObjectMetaBuilder {
158158
Labels::recommended(object_labels).context(RecommendedLabelsSnafu)?;
159159

160160
self.labels
161-
.get_or_insert(Labels::new())
161+
.get_or_insert_with(Labels::new)
162162
.extend(recommended_labels);
163163

164164
Ok(self)

crates/stackable-operator/src/builder/pod/container.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,15 @@ impl ContainerBuilder {
305305

306306
pub fn lifecycle_post_start(&mut self, post_start: LifecycleHandler) -> &mut Self {
307307
self.lifecycle
308-
.get_or_insert(Lifecycle::default())
308+
.get_or_insert_with(Lifecycle::default)
309309
.post_start = Some(post_start);
310310
self
311311
}
312312

313313
pub fn lifecycle_pre_stop(&mut self, pre_stop: LifecycleHandler) -> &mut Self {
314-
self.lifecycle.get_or_insert(Lifecycle::default()).pre_stop = Some(pre_stop);
314+
self.lifecycle
315+
.get_or_insert_with(Lifecycle::default)
316+
.pre_stop = Some(pre_stop);
315317
self
316318
}
317319

crates/stackable-operator/src/builder/pod/security.rs

Lines changed: 135 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -189,92 +189,116 @@ impl PodSecurityContextBuilder {
189189
}
190190

191191
pub fn se_linux_level(&mut self, level: &str) -> &mut Self {
192-
self.pod_security_context.se_linux_options =
193-
Some(self.pod_security_context.se_linux_options.clone().map_or(
194-
SELinuxOptions {
195-
level: Some(level.to_string()),
196-
..SELinuxOptions::default()
197-
},
198-
|o| SELinuxOptions {
199-
level: Some(level.to_string()),
200-
..o
201-
},
202-
));
192+
self.pod_security_context.se_linux_options = Some(
193+
self.pod_security_context
194+
.se_linux_options
195+
.clone()
196+
.map_or_else(
197+
|| SELinuxOptions {
198+
level: Some(level.to_string()),
199+
..SELinuxOptions::default()
200+
},
201+
|o| SELinuxOptions {
202+
level: Some(level.to_string()),
203+
..o
204+
},
205+
),
206+
);
203207
self
204208
}
205209

206210
pub fn se_linux_role(&mut self, role: &str) -> &mut Self {
207-
self.pod_security_context.se_linux_options =
208-
Some(self.pod_security_context.se_linux_options.clone().map_or(
209-
SELinuxOptions {
210-
role: Some(role.to_string()),
211-
..SELinuxOptions::default()
212-
},
213-
|o| SELinuxOptions {
214-
role: Some(role.to_string()),
215-
..o
216-
},
217-
));
211+
self.pod_security_context.se_linux_options = Some(
212+
self.pod_security_context
213+
.se_linux_options
214+
.clone()
215+
.map_or_else(
216+
|| SELinuxOptions {
217+
role: Some(role.to_string()),
218+
..SELinuxOptions::default()
219+
},
220+
|o| SELinuxOptions {
221+
role: Some(role.to_string()),
222+
..o
223+
},
224+
),
225+
);
218226
self
219227
}
220228

221229
pub fn se_linux_type(&mut self, type_: &str) -> &mut Self {
222-
self.pod_security_context.se_linux_options =
223-
Some(self.pod_security_context.se_linux_options.clone().map_or(
224-
SELinuxOptions {
225-
type_: Some(type_.to_string()),
226-
..SELinuxOptions::default()
227-
},
228-
|o| SELinuxOptions {
229-
type_: Some(type_.to_string()),
230-
..o
231-
},
232-
));
230+
self.pod_security_context.se_linux_options = Some(
231+
self.pod_security_context
232+
.se_linux_options
233+
.clone()
234+
.map_or_else(
235+
|| SELinuxOptions {
236+
type_: Some(type_.to_string()),
237+
..SELinuxOptions::default()
238+
},
239+
|o| SELinuxOptions {
240+
type_: Some(type_.to_string()),
241+
..o
242+
},
243+
),
244+
);
233245
self
234246
}
235247

236248
pub fn se_linux_user(&mut self, user: &str) -> &mut Self {
237-
self.pod_security_context.se_linux_options =
238-
Some(self.pod_security_context.se_linux_options.clone().map_or(
239-
SELinuxOptions {
240-
user: Some(user.to_string()),
241-
..SELinuxOptions::default()
242-
},
243-
|o| SELinuxOptions {
244-
user: Some(user.to_string()),
245-
..o
246-
},
247-
));
249+
self.pod_security_context.se_linux_options = Some(
250+
self.pod_security_context
251+
.se_linux_options
252+
.clone()
253+
.map_or_else(
254+
|| SELinuxOptions {
255+
user: Some(user.to_string()),
256+
..SELinuxOptions::default()
257+
},
258+
|o| SELinuxOptions {
259+
user: Some(user.to_string()),
260+
..o
261+
},
262+
),
263+
);
248264
self
249265
}
250266

251267
pub fn seccomp_profile_localhost(&mut self, profile: &str) -> &mut Self {
252-
self.pod_security_context.seccomp_profile =
253-
Some(self.pod_security_context.seccomp_profile.clone().map_or(
254-
SeccompProfile {
255-
localhost_profile: Some(profile.to_string()),
256-
..SeccompProfile::default()
257-
},
258-
|o| SeccompProfile {
259-
localhost_profile: Some(profile.to_string()),
260-
..o
261-
},
262-
));
268+
self.pod_security_context.seccomp_profile = Some(
269+
self.pod_security_context
270+
.seccomp_profile
271+
.clone()
272+
.map_or_else(
273+
|| SeccompProfile {
274+
localhost_profile: Some(profile.to_string()),
275+
..SeccompProfile::default()
276+
},
277+
|o| SeccompProfile {
278+
localhost_profile: Some(profile.to_string()),
279+
..o
280+
},
281+
),
282+
);
263283
self
264284
}
265285

266286
pub fn seccomp_profile_type(&mut self, type_: &str) -> &mut Self {
267-
self.pod_security_context.seccomp_profile =
268-
Some(self.pod_security_context.seccomp_profile.clone().map_or(
269-
SeccompProfile {
270-
type_: type_.to_string(),
271-
..SeccompProfile::default()
272-
},
273-
|o| SeccompProfile {
274-
type_: type_.to_string(),
275-
..o
276-
},
277-
));
287+
self.pod_security_context.seccomp_profile = Some(
288+
self.pod_security_context
289+
.seccomp_profile
290+
.clone()
291+
.map_or_else(
292+
|| SeccompProfile {
293+
type_: type_.to_string(),
294+
..SeccompProfile::default()
295+
},
296+
|o| SeccompProfile {
297+
type_: type_.to_string(),
298+
..o
299+
},
300+
),
301+
);
278302
self
279303
}
280304

@@ -292,47 +316,59 @@ impl PodSecurityContextBuilder {
292316
}
293317

294318
pub fn win_credential_spec(&mut self, spec: &str) -> &mut Self {
295-
self.pod_security_context.windows_options =
296-
Some(self.pod_security_context.windows_options.clone().map_or(
297-
WindowsSecurityContextOptions {
298-
gmsa_credential_spec: Some(spec.to_string()),
299-
..WindowsSecurityContextOptions::default()
300-
},
301-
|o| WindowsSecurityContextOptions {
302-
gmsa_credential_spec: Some(spec.to_string()),
303-
..o
304-
},
305-
));
319+
self.pod_security_context.windows_options = Some(
320+
self.pod_security_context
321+
.windows_options
322+
.clone()
323+
.map_or_else(
324+
|| WindowsSecurityContextOptions {
325+
gmsa_credential_spec: Some(spec.to_string()),
326+
..WindowsSecurityContextOptions::default()
327+
},
328+
|o| WindowsSecurityContextOptions {
329+
gmsa_credential_spec: Some(spec.to_string()),
330+
..o
331+
},
332+
),
333+
);
306334
self
307335
}
308336

309337
pub fn win_credential_spec_name(&mut self, name: &str) -> &mut Self {
310-
self.pod_security_context.windows_options =
311-
Some(self.pod_security_context.windows_options.clone().map_or(
312-
WindowsSecurityContextOptions {
313-
gmsa_credential_spec_name: Some(name.to_string()),
314-
..WindowsSecurityContextOptions::default()
315-
},
316-
|o| WindowsSecurityContextOptions {
317-
gmsa_credential_spec_name: Some(name.to_string()),
318-
..o
319-
},
320-
));
338+
self.pod_security_context.windows_options = Some(
339+
self.pod_security_context
340+
.windows_options
341+
.clone()
342+
.map_or_else(
343+
|| WindowsSecurityContextOptions {
344+
gmsa_credential_spec_name: Some(name.to_string()),
345+
..WindowsSecurityContextOptions::default()
346+
},
347+
|o| WindowsSecurityContextOptions {
348+
gmsa_credential_spec_name: Some(name.to_string()),
349+
..o
350+
},
351+
),
352+
);
321353
self
322354
}
323355

324356
pub fn win_run_as_user_name(&mut self, name: &str) -> &mut Self {
325-
self.pod_security_context.windows_options =
326-
Some(self.pod_security_context.windows_options.clone().map_or(
327-
WindowsSecurityContextOptions {
328-
run_as_user_name: Some(name.to_string()),
329-
..WindowsSecurityContextOptions::default()
330-
},
331-
|o| WindowsSecurityContextOptions {
332-
run_as_user_name: Some(name.to_string()),
333-
..o
334-
},
335-
));
357+
self.pod_security_context.windows_options = Some(
358+
self.pod_security_context
359+
.windows_options
360+
.clone()
361+
.map_or_else(
362+
|| WindowsSecurityContextOptions {
363+
run_as_user_name: Some(name.to_string()),
364+
..WindowsSecurityContextOptions::default()
365+
},
366+
|o| WindowsSecurityContextOptions {
367+
run_as_user_name: Some(name.to_string()),
368+
..o
369+
},
370+
),
371+
);
336372
self
337373
}
338374
}

crates/stackable-operator/src/commons/product_image_selection.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ impl ProductImage {
122122
match &self.image_selection {
123123
ProductImageSelection::Custom(image_selection) => {
124124
let image = ImageRef::parse(&image_selection.custom);
125-
let image_tag_or_hash = image.tag.or(image.hash).unwrap_or("latest".to_string());
125+
let image_tag_or_hash = image
126+
.tag
127+
.or(image.hash)
128+
.unwrap_or_else(|| "latest".to_string());
126129

127130
let app_version = format!("{product_version}-{image_tag_or_hash}");
128131
let app_version_label_value = Self::prepare_app_version_label_value(&app_version)?;

crates/stackable-operator/src/crd/authentication/ldap/v1alpha1_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl AuthenticationProvider {
5656
/// Returns the port to be used, which is either user configured or defaulted based upon TLS usage
5757
pub fn port(&self) -> u16 {
5858
self.port
59-
.unwrap_or(if self.tls.uses_tls() { 636 } else { 389 })
59+
.unwrap_or_else(|| if self.tls.uses_tls() { 636 } else { 389 })
6060
}
6161

6262
/// This functions adds

crates/stackable-operator/src/crd/authentication/oidc/v1alpha1_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl AuthenticationProvider {
108108
/// Returns the port to be used, which is either user configured or defaulted based upon TLS usage
109109
pub fn port(&self) -> u16 {
110110
self.port
111-
.unwrap_or(if self.tls.uses_tls() { 443 } else { 80 })
111+
.unwrap_or_else(|| if self.tls.uses_tls() { 443 } else { 80 })
112112
}
113113

114114
/// Returns the path of the files containing client id and secret in case they are given.

crates/stackable-operator/src/crd/s3/connection/v1alpha1_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl ConnectionSpec {
7676
/// Returns the port to be used, which is either user configured or defaulted based upon TLS usage
7777
pub fn port(&self) -> u16 {
7878
self.port
79-
.unwrap_or(if self.tls.uses_tls() { 443 } else { 80 })
79+
.unwrap_or_else(|| if self.tls.uses_tls() { 443 } else { 80 })
8080
}
8181

8282
/// This functions adds

crates/stackable-operator/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// Nursery lints
1414
// #![deny(clippy::nursery)]
1515
#![deny(clippy::use_self)]
16+
#![deny(clippy::or_fun_call)]
1617

1718
//! ## Crate Features
1819
//!

crates/stackable-operator/src/product_config_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ pub fn validate_all_roles_and_groups_config(
225225
let mut result = HashMap::new();
226226

227227
for (role, role_group) in role_config {
228-
let role_entry = result.entry(role.clone()).or_insert(HashMap::new());
228+
let role_entry = result.entry(role.clone()).or_insert_with(HashMap::new);
229229

230230
for (group, properties_by_kind) in role_group {
231231
role_entry.insert(

0 commit comments

Comments
 (0)