From fc8494b45fcff1d1aafa542d9cad1c42de8d9b98 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Wed, 2 Jan 2019 18:55:49 -0500 Subject: [PATCH] clippy: unwrap_or/ok_or(function call) unwrap_or_else/ok_or_else --- ofborg/src/asynccmd.rs | 4 +--- ofborg/src/commitstatus.rs | 2 +- ofborg/src/config.rs | 2 +- ofborg/src/easyamqp.rs | 12 ++++++------ ofborg/src/nix.rs | 2 +- ofborg/src/notifyworker.rs | 4 ++-- ofborg/src/tasks/githubcommentposter.rs | 2 +- ofborg/src/tasks/massrebuilder.rs | 4 ++-- ofborg/src/worker.rs | 4 ++-- 9 files changed, 17 insertions(+), 19 deletions(-) diff --git a/ofborg/src/asynccmd.rs b/ofborg/src/asynccmd.rs index a3b5d3e..491840f 100644 --- a/ofborg/src/asynccmd.rs +++ b/ofborg/src/asynccmd.rs @@ -196,13 +196,11 @@ impl SpawnedAsyncCmd { pub fn wait(self) -> Result { self.waiter.join() .map_err(|_err| io::Error::new(io::ErrorKind::Other, "Couldn't join thread.")) - .and_then(|opt| opt.ok_or(io::Error::new(io::ErrorKind::Other, "Thread didn't return an exit status."))) + .and_then(|opt| opt.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "Thread didn't return an exit status."))) .and_then(|res| res) } } - - #[cfg(test)] mod tests { use super::AsyncCmd; diff --git a/ofborg/src/commitstatus.rs b/ofborg/src/commitstatus.rs index 9b955c1..5eddc74 100644 --- a/ofborg/src/commitstatus.rs +++ b/ofborg/src/commitstatus.rs @@ -33,7 +33,7 @@ impl<'a> CommitStatus<'a> { } pub fn set_url(&mut self, url: Option) { - self.url = url.unwrap_or(String::from("")) + self.url = url.unwrap_or_else(|| String::from("")) } pub fn set_with_description(&mut self, description: &str, state: hubcaps::statuses::State) { diff --git a/ofborg/src/config.rs b/ofborg/src/config.rs index d439c06..4a90596 100644 --- a/ofborg/src/config.rs +++ b/ofborg/src/config.rs @@ -158,7 +158,7 @@ impl RabbitMQConfig { self.username, self.password, self.host, - self.virtualhost.clone().unwrap_or("/".to_owned()), + self.virtualhost.clone().unwrap_or_else(|| "/".to_owned()), ) } } diff --git a/ofborg/src/easyamqp.rs b/ofborg/src/easyamqp.rs index 031bea8..4d4977b 100644 --- a/ofborg/src/easyamqp.rs +++ b/ofborg/src/easyamqp.rs @@ -301,7 +301,7 @@ pub fn session_from_config(config: &RabbitMQConfig) -> Result 5671, amqp::AMQPScheme::AMQP => 5672, }, - vhost: config.virtualhost.clone().unwrap_or("/".to_owned()), + vhost: config.virtualhost.clone().unwrap_or_else(|| "/".to_owned()), login: config.username.clone(), password: config.password.clone(), scheme, @@ -349,7 +349,7 @@ impl TypedWrappers for amqp::Channel { config.no_ack, config.exclusive, config.no_wait, - config.arguments.unwrap_or(amqp::Table::new()), + config.arguments.unwrap_or_else(amqp::Table::new), ) } @@ -365,7 +365,7 @@ impl TypedWrappers for amqp::Channel { config.auto_delete, config.internal, config.no_wait, - config.arguments.unwrap_or(amqp::Table::new()), + config.arguments.unwrap_or_else(amqp::Table::new), ) } @@ -381,7 +381,7 @@ impl TypedWrappers for amqp::Channel { config.exclusive, config.auto_delete, config.no_wait, - config.arguments.unwrap_or(amqp::Table::new()), + config.arguments.unwrap_or_else(amqp::Table::new), ) } @@ -392,9 +392,9 @@ impl TypedWrappers for amqp::Channel { self.queue_bind( config.queue, config.exchange, - config.routing_key.unwrap_or("".to_owned()), + config.routing_key.unwrap_or_else(|| "".to_owned()), config.no_wait, - config.arguments.unwrap_or(amqp::Table::new()), + config.arguments.unwrap_or_else(amqp::Table::new), ) } } diff --git a/ofborg/src/nix.rs b/ofborg/src/nix.rs index bde30fa..7e3679e 100644 --- a/ofborg/src/nix.rs +++ b/ofborg/src/nix.rs @@ -216,7 +216,7 @@ impl Nix { let status = cmd.stdout(Stdio::from(stdout)) .stderr(Stdio::from(stderr)) .status() - .expect(format!("Running a program ...").as_ref()); + .expect("Running a program ..."); reader.seek(SeekFrom::Start(0)).expect( "Seeking to Start(0)", diff --git a/ofborg/src/notifyworker.rs b/ofborg/src/notifyworker.rs index b406806..e67a3b8 100644 --- a/ofborg/src/notifyworker.rs +++ b/ofborg/src/notifyworker.rs @@ -72,8 +72,8 @@ impl<'a> NotificationReceiver for ChannelNotificationReceiver<'a> { .unwrap(); } Action::Publish(msg) => { - let exch = msg.exchange.clone().unwrap_or("".to_owned()); - let key = msg.routing_key.clone().unwrap_or("".to_owned()); + let exch = msg.exchange.clone().unwrap_or_else(|| "".to_owned()); + let key = msg.routing_key.clone().unwrap_or_else(|| "".to_owned()); let props = msg.properties.unwrap_or( BasicProperties { ..Default::default() }, diff --git a/ofborg/src/tasks/githubcommentposter.rs b/ofborg/src/tasks/githubcommentposter.rs index c13b9d4..cd78ba1 100644 --- a/ofborg/src/tasks/githubcommentposter.rs +++ b/ofborg/src/tasks/githubcommentposter.rs @@ -80,7 +80,7 @@ fn result_to_check(result: &LegacyBuildResult, timestamp: DateTime) -> Chec result.skipped_attrs.clone() ] .into_iter() - .map(|opt| opt.unwrap_or(vec![])) + .map(|opt| opt.unwrap_or_else(|| vec![])) .flat_map(|list| list.into_iter().map(|attr| format!("-A {}", attr))) .collect(); all_attrs.sort(); diff --git a/ofborg/src/tasks/massrebuilder.rs b/ofborg/src/tasks/massrebuilder.rs index 8ca6d48..62557f8 100644 --- a/ofborg/src/tasks/massrebuilder.rs +++ b/ofborg/src/tasks/massrebuilder.rs @@ -251,13 +251,13 @@ impl worker::SimpleWorker for MassRebuildWorker Consumer for Worker { .unwrap(); } Action::Publish(msg) => { - let exch = msg.exchange.clone().unwrap_or("".to_owned()); - let key = msg.routing_key.clone().unwrap_or("".to_owned()); + let exch = msg.exchange.clone().unwrap_or_else(|| "".to_owned()); + let key = msg.routing_key.clone().unwrap_or_else(|| "".to_owned()); let props = msg.properties.unwrap_or( BasicProperties { ..Default::default() },