diff --git a/edgelet/edgelet-core/src/settings.rs b/edgelet/edgelet-core/src/settings.rs index 7077b53fd77..242bf633e5e 100644 --- a/edgelet/edgelet-core/src/settings.rs +++ b/edgelet/edgelet-core/src/settings.rs @@ -114,13 +114,12 @@ impl ManualDeviceConnectionString { let mut device_id = None; let mut hub = None; - let parts: Vec<&str> = self.device_connection_string.split(';').collect(); - for p in parts { - let s: Vec<&str> = p.split('=').collect(); - match s[0] { - SHAREDACCESSKEY_KEY => key = Some(s[1].to_string()), - DEVICEID_KEY => device_id = Some(s[1].to_string()), - HOSTNAME_KEY => hub = Some(s[1].to_string()), + for sections in self.device_connection_string.split(';') { + let mut parts = sections.split('='); + match parts.next() { + Some(SHAREDACCESSKEY_KEY) => key = parts.next().map(String::from), + Some(DEVICEID_KEY) => device_id = parts.next().map(String::from), + Some(HOSTNAME_KEY) => hub = parts.next().map(String::from), _ => (), // Ignore extraneous component in the connection string } } diff --git a/edgelet/edgelet-core/src/watchdog.rs b/edgelet/edgelet-core/src/watchdog.rs index ca05677d3df..51aa47cf00e 100644 --- a/edgelet/edgelet-core/src/watchdog.rs +++ b/edgelet/edgelet-core/src/watchdog.rs @@ -99,7 +99,9 @@ where .stop(name, Some(EDGE_RUNTIME_STOP_TIME)) .or_else(|err| match (&err).into() { ModuleRuntimeErrorReason::NotFound => Ok(()), - _ => Err(Error::from(err.context(ErrorKind::ModuleRuntime))), + ModuleRuntimeErrorReason::Other => { + Err(Error::from(err.context(ErrorKind::ModuleRuntime))) + } }) } @@ -139,15 +141,16 @@ where }) }) .fold(0, move |exec_count: u32, result: Option| { - result - .and_then(|e| { + result.map_or_else( + || Ok(0), + |e| { if max_retries.compare(exec_count) == Ordering::Greater { - Some(Ok(exec_count + 1)) + Ok(exec_count + 1) } else { - Some(Err(e)) + Err(e) } - }) - .unwrap_or_else(|| Ok(0)) + }, + ) }) .map(|_| ()) } diff --git a/edgelet/edgelet-docker/src/runtime.rs b/edgelet/edgelet-docker/src/runtime.rs index da8adcdab20..5ba5db3e1eb 100644 --- a/edgelet/edgelet-docker/src/runtime.rs +++ b/edgelet/edgelet-docker/src/runtime.rs @@ -199,14 +199,12 @@ impl MakeModuleRuntime for DockerModuleRuntime { _: impl GetTrustBundle, ) -> Self::Future { info!("Initializing module runtime..."); - - // Clippy incorrectly flags the use of `.map(..).unwrap_or_else(..)` code as being replaceable - // with `.ok().map_or_else`. This is incorrect because `.ok()` will result in the error being dropped. - // So we suppress this lint. There's an open issue for this on the Clippy repo: - // https://github.com/rust-lang/rust-clippy/issues/3730 - #[allow(clippy::result_map_unwrap_or_else)] - let created = init_client(settings.moby_runtime().uri()) - .map(|client| { + let created = init_client(settings.moby_runtime().uri()).map_or_else( + |err| { + log_failure(Level::Warn, &err); + future::Either::B(Err(err).into_future()) + }, + |client| { let network_id = settings.moby_runtime().network().name().to_string(); let (enable_i_pv6, ipam) = get_ipv6_settings(settings.moby_runtime().network()); info!("Using runtime network id {}", network_id); @@ -253,11 +251,8 @@ impl MakeModuleRuntime for DockerModuleRuntime { }); future::Either::A(fut) - }) - .unwrap_or_else(|err| { - log_failure(Level::Warn, &err); - future::Either::B(Err(err).into_future()) - }); + }, + ); Box::new(created) } @@ -334,7 +329,7 @@ impl ModuleRuntime for DockerModuleRuntime { let result = module .config() .clone_create_options() - .and_then(|create_options| { + .map(|create_options| { // merge environment variables let merged_env = DockerModuleRuntime::merge_env(create_options.env(), module.env()); @@ -357,9 +352,7 @@ impl ModuleRuntime for DockerModuleRuntime { // Here we don't add the container to the iot edge docker network as the edge-agent is expected to do that. // It contains the logic to add a container to the iot edge network only if a network is not already specified. - - Ok(self - .client + self.client .container_api() .container_create(create_options, module.name()) .then(|result| match result { @@ -370,7 +363,7 @@ impl ModuleRuntime for DockerModuleRuntime { module.name().to_string(), )), )), - })) + }) }) .into_future() .flatten() @@ -478,9 +471,9 @@ impl ModuleRuntime for DockerModuleRuntime { } #[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)] - let wait_timeout = wait_before_kill.and_then(|s| match s.as_secs() { - s if s > i32::max_value() as u64 => Some(i32::max_value()), - s => Some(s as i32), + let wait_timeout = wait_before_kill.map(|s| match s.as_secs() { + s if s > i32::max_value() as u64 => i32::max_value(), + s => s as i32, }); Box::new( diff --git a/edgelet/edgelet-docker/tests/runtime.rs b/edgelet/edgelet-docker/tests/runtime.rs index ad2bbf8aa9c..d658a755fc9 100644 --- a/edgelet/edgelet-docker/tests/runtime.rs +++ b/edgelet/edgelet-docker/tests/runtime.rs @@ -120,7 +120,7 @@ fn make_get_networks_handler( } fn make_create_network_handler( - on_post: impl Fn(Request) -> () + Clone + Send + 'static, + on_post: impl Fn(Request) + Clone + Send + 'static, ) -> impl Fn(Request) -> ResponseFuture + Clone { move |req| { on_post(req); @@ -154,7 +154,7 @@ fn not_found_handler(_: Request) -> ResponseFuture { fn make_network_handler( on_get: impl Fn() -> String + Clone + Send + 'static, - on_post: impl Fn(Request) -> () + Clone + Send + 'static, + on_post: impl Fn(Request) + Clone + Send + 'static, ) -> impl Fn(Request) -> Box, Error = HyperError> + Send> + Clone { let dispatch_table = routes!( diff --git a/edgelet/edgelet-http-mgmt/src/client/module.rs b/edgelet/edgelet-http-mgmt/src/client/module.rs index bb675f0e8ad..4cadb35dcd6 100644 --- a/edgelet/edgelet-http-mgmt/src/client/module.rs +++ b/edgelet/edgelet-http-mgmt/src/client/module.rs @@ -191,11 +191,11 @@ impl ModuleRuntime for ModuleClient { ) }) .then(|result| match result { + other @ Ok(_) => other, Err(e) => match e.kind() { ErrorKind::NotModified => Ok(()), _ => Err(e), }, - other => other, }); Box::new(start) } @@ -214,11 +214,11 @@ impl ModuleRuntime for ModuleClient { ) }) .then(|result| match result { + other @ Ok(_) => other, Err(e) => match e.kind() { ErrorKind::NotModified => Ok(()), _ => Err(e), }, - other => other, }); Box::new(stop) } @@ -237,11 +237,11 @@ impl ModuleRuntime for ModuleClient { ) }) .then(|result| match result { + other @ Ok(_) => other, Err(e) => match e.kind() { ErrorKind::NotModified => Ok(()), _ => Err(e), }, - other => other, }); Box::new(restart) } diff --git a/edgelet/hsm-rs/src/crypto.rs b/edgelet/hsm-rs/src/crypto.rs index 645ffd05659..2828bbdb2b0 100644 --- a/edgelet/hsm-rs/src/crypto.rs +++ b/edgelet/hsm-rs/src/crypto.rs @@ -189,7 +189,7 @@ fn make_certification_props(props: &CertificateProperties) -> Result CERTIFICATE_TYPE_CERTIFICATE_TYPE_CLIENT, CertificateType::Server => CERTIFICATE_TYPE_CERTIFICATE_TYPE_SERVER, CertificateType::Ca => CERTIFICATE_TYPE_CERTIFICATE_TYPE_CA, - _ => CERTIFICATE_TYPE_CERTIFICATE_TYPE_UNKNOWN, + CertificateType::Unknown => CERTIFICATE_TYPE_CERTIFICATE_TYPE_UNKNOWN, }; let result = unsafe { set_certificate_type(handle, c_cert_type) }; match result { @@ -281,9 +281,8 @@ impl CreateCertificate for Crypto { CString::new(alias) .ok() - .and_then(|c_alias| { + .map(|c_alias| { unsafe { if_fn(self.handle, c_alias.as_ptr()) }; - Some(()) }) .ok_or_else(|| ErrorKind::ToCStr)?; Ok(()) diff --git a/edgelet/iotedge-proxy/src/routine.rs b/edgelet/iotedge-proxy/src/routine.rs index fa1a6febacb..e3272be70aa 100644 --- a/edgelet/iotedge-proxy/src/routine.rs +++ b/edgelet/iotedge-proxy/src/routine.rs @@ -96,7 +96,7 @@ fn start_api( )) }) }) - .and_then(move |addr| { + .map(move |addr| { let new_service = ApiService::new(); let server = Server::bind(&addr) @@ -109,7 +109,7 @@ fn start_api( settings.entrypoint(), ); - Ok(server) + server }) .into_future() .flatten() diff --git a/edgelet/iotedged/src/lib.rs b/edgelet/iotedged/src/lib.rs index 588eb972cff..6c20e310187 100644 --- a/edgelet/iotedged/src/lib.rs +++ b/edgelet/iotedged/src/lib.rs @@ -1617,9 +1617,9 @@ fn manual_provision_connection_string( InitializeErrorReason::ManualProvisioningClient, ))) }) - .and_then(|k| { + .map(|k| { let derived_key_store = DerivedKeyStore::new(k.clone()); - Ok((derived_key_store, prov_result, k)) + (derived_key_store, prov_result, k) }) }); tokio_runtime.block_on(provision) @@ -1775,9 +1775,9 @@ fn external_provision_tpm( ), ))) }) - .and_then(|k| { + .map(|k| { let derived_key_store = DerivedKeyStore::new(k.clone()); - Ok((derived_key_store, k)) + (derived_key_store, k) }) } diff --git a/edgelet/kube-client/src/client.rs b/edgelet/kube-client/src/client.rs index 917ee42fd33..294bf079118 100644 --- a/edgelet/kube-client/src/client.rs +++ b/edgelet/kube-client/src/client.rs @@ -147,7 +147,9 @@ where self.request(req, true) .and_then(|response| match response { ListResponse::Ok(list) => Ok(list), - _ => Err(Error::from(ErrorKind::Response(RequestType::ConfigMapList))), + ListResponse::Other(_) => { + Err(Error::from(ErrorKind::Response(RequestType::ConfigMapList))) + } }) .map_err(|err| { Error::from(err.context(ErrorKind::Response(RequestType::ConfigMapList))) @@ -265,7 +267,7 @@ where self.request(req, true) .and_then(|response| match response { ListResponse::Ok(deployments) => Ok(deployments), - _ => Err(Error::from(ErrorKind::Response( + ListResponse::Other(_) => Err(Error::from(ErrorKind::Response( RequestType::DeploymentList, ))), }) @@ -379,7 +381,9 @@ where self.request(req, true) .and_then(|response| match response { ListResponse::Ok(list) => Ok(list), - _ => Err(Error::from(ErrorKind::Response(RequestType::PodList))), + ListResponse::Other(_) => { + Err(Error::from(ErrorKind::Response(RequestType::PodList))) + } }) .map_err(|err| { Error::from(err.context(ErrorKind::Response(RequestType::PodList))) @@ -396,7 +400,9 @@ where self.request(req, true) .and_then(|response| match response { ListResponse::Ok(list) => Ok(list), - _ => Err(Error::from(ErrorKind::Response(RequestType::NodeList))), + ListResponse::Other(_) => { + Err(Error::from(ErrorKind::Response(RequestType::NodeList))) + } }) .map_err(|err| { Error::from(err.context(ErrorKind::Response(RequestType::NodeList))) @@ -422,7 +428,9 @@ where self.request(req, false) .and_then(|response| match response { ListResponse::Ok(list) => Ok(list), - _ => Err(Error::from(ErrorKind::Response(RequestType::SecretList))), + ListResponse::Other(_) => { + Err(Error::from(ErrorKind::Response(RequestType::SecretList))) + } }) .map_err(|err| { Error::from(err.context(ErrorKind::Response(RequestType::SecretList))) @@ -536,7 +544,7 @@ where self.request(req, true) .and_then(|response| match response { ListResponse::Ok(list) => Ok(list), - _ => Err(Error::from(ErrorKind::Response( + ListResponse::Other(_) => Err(Error::from(ErrorKind::Response( RequestType::ServiceAccountList, ))), }) @@ -598,9 +606,9 @@ where api_core::ReadNamespacedServiceAccountResponse::Ok(service_account) => { Ok(service_account) } - _ => Err(Error::from(ErrorKind::Response( - RequestType::ServiceAccountGet, - ))), + api_core::ReadNamespacedServiceAccountResponse::Other(_) => Err(Error::from( + ErrorKind::Response(RequestType::ServiceAccountGet), + )), }) .map_err(|err| { Error::from(err.context(ErrorKind::Response(RequestType::ServiceAccountGet))) diff --git a/edgelet/systemd/src/linux.rs b/edgelet/systemd/src/linux.rs index 46d453c573e..a42ef141cf4 100644 --- a/edgelet/systemd/src/linux.rs +++ b/edgelet/systemd/src/linux.rs @@ -275,7 +275,7 @@ mod tests { match socket { Socket::Inet(n, _) => unistd::close(n).unwrap(), Socket::Unix(u) => unistd::close(u).unwrap(), - _ => (), + Socket::Unknown => (), } } }