From 4d4da1c52afdfca0390048cf9ad3c649a41bd5e1 Mon Sep 17 00:00:00 2001 From: Nicholas Rempel Date: Wed, 27 Oct 2021 15:45:32 -0700 Subject: [PATCH] cargo clippy --fix --- epp-client-macros/src/lib.rs | 4 ++-- epp-client/src/config.rs | 16 ++++---------- epp-client/src/connection/client.rs | 21 +++++++------------ epp-client/src/connection/registry.rs | 19 ++++++++--------- epp-client/src/epp/object.rs | 2 +- epp-client/src/epp/object/data.rs | 6 +++--- epp-client/src/epp/request.rs | 15 +++++-------- epp-client/src/epp/request/contact/check.rs | 2 +- epp-client/src/epp/request/contact/create.rs | 4 ++-- epp-client/src/epp/request/contact/update.rs | 2 +- epp-client/src/epp/request/domain/check.rs | 2 +- .../src/epp/request/domain/rgp/report.rs | 2 +- epp-client/src/epp/request/host/check.rs | 2 +- epp-client/src/epp/response.rs | 4 ++-- epp-client/src/epp/xml/quick_xml.rs | 2 +- epp-client/src/error.rs | 2 +- epp-client/src/tests/mod.rs | 4 ++-- 17 files changed, 45 insertions(+), 64 deletions(-) diff --git a/epp-client-macros/src/lib.rs b/epp-client-macros/src/lib.rs index 83eca6c..66f7b22 100644 --- a/epp-client-macros/src/lib.rs +++ b/epp-client-macros/src/lib.rs @@ -17,11 +17,11 @@ fn element_name_macro(ast: &syn::DeriveInput) -> TokenStream { let mut elem_name = ast.ident.to_string(); let (impl_generics, type_generics, _) = &ast.generics.split_for_impl(); - if ast.attrs.len() > 0 { + if !ast.attrs.is_empty() { let attribute = &ast.attrs[0]; match attribute.parse_meta() { Ok(syn::Meta::List(meta)) => { - if meta.nested.len() > 0 { + if !meta.nested.is_empty() { elem_name = match &meta.nested[0] { syn::NestedMeta::Meta(syn::Meta::NameValue(v)) => match &v.lit { syn::Lit::Str(lit) => lit.value(), diff --git a/epp-client/src/config.rs b/epp-client/src/config.rs index 438ad0d..7b9cce2 100644 --- a/epp-client/src/config.rs +++ b/epp-client/src/config.rs @@ -137,31 +137,23 @@ impl EppClientConnection { } /// Parses the client certificate chain fn client_certificate(&self) -> Option> { - match &self.tls_files { - Some(tls) => Some( - rustls_pemfile::certs(&mut io::BufReader::new( + self.tls_files.as_ref().map(|tls| rustls_pemfile::certs(&mut io::BufReader::new( fs::File::open(tls.cert_chain.to_string()).unwrap(), )) .unwrap() .iter() .map(|v| Certificate(v.clone())) - .collect(), - ), - None => None, - } + .collect()) } /// Parses the client RSA private key fn key(&self) -> Option { - match &self.tls_files { - Some(tls) => Some(rustls::PrivateKey( + self.tls_files.as_ref().map(|tls| rustls::PrivateKey( rustls_pemfile::rsa_private_keys(&mut io::BufReader::new( fs::File::open(tls.key.to_string()).unwrap(), )) .unwrap()[0] .clone(), - )), - None => None, - } + )) } } diff --git a/epp-client/src/connection/client.rs b/epp-client/src/connection/client.rs index b1cc53d..3d054d7 100644 --- a/epp-client/src/connection/client.rs +++ b/epp-client/src/connection/client.rs @@ -50,19 +50,14 @@ async fn connect(registry: &'static str) -> Result> { let (tx, rx) = mpsc::channel(); tokio::spawn(async move { - let stream = epp_connect(®istry_creds).await.unwrap(); + let stream = epp_connect(registry_creds).await.unwrap(); let credentials = registry_creds.credentials(); let ext_uris = registry_creds.ext_uris(); - let ext_uris = match ext_uris { - Some(uris) => Some( - uris + let ext_uris = ext_uris.map(|uris| uris .iter() .map(|u| u.to_string()) - .collect::>() - ), - None => None, - }; + .collect::>()); let connection = EppConnection::new( registry.to_string(), @@ -119,9 +114,9 @@ impl EppClient { /// Makes a login request to the registry and initializes an EppClient instance with it async fn build(connection: EppConnection, credentials: (String, String), ext_uris: Option>) -> Result> { let mut client = EppClient { - connection: connection, - credentials: credentials, - ext_uris: ext_uris, + connection, + credentials, + ext_uris, // client_tr_id_fn: Arc::new(default_client_tr_id_fn), }; @@ -164,12 +159,12 @@ impl EppClient { /// Accepts raw EPP XML and returns the raw EPP XML response to it. /// Not recommended for direct use but sometimes can be useful for debugging pub async fn transact_xml(&mut self, xml: &str) -> Result> { - self.connection.transact(&xml).await + self.connection.transact(xml).await } /// Returns the greeting received on establishment of the connection in raw xml form pub fn xml_greeting(&self) -> String { - return String::from(&self.connection.greeting) + String::from(&self.connection.greeting) } /// Returns the greeting received on establishment of the connection as an `EppGreeting` diff --git a/epp-client/src/connection/registry.rs b/epp-client/src/connection/registry.rs index 2036107..3f7ac77 100644 --- a/epp-client/src/connection/registry.rs +++ b/epp-client/src/connection/registry.rs @@ -38,9 +38,9 @@ impl EppConnection { debug!("{}: greeting: {}", registry, greeting); Ok(EppConnection { - registry: registry, - stream: stream, - greeting: greeting + registry, + stream, + greeting }) } @@ -64,7 +64,7 @@ impl EppConnection { let len_u32: [u8; 4] = u32::to_be_bytes(len.try_into()?); buf[..4].clone_from_slice(&len_u32); - buf[4..].clone_from_slice(&content.as_bytes()); + buf[4..].clone_from_slice(content.as_bytes()); self.write(&buf).await } @@ -89,7 +89,7 @@ impl EppConnection { debug!("{}: Read: {} bytes", self.registry, read); buf.extend_from_slice(&read_buf[0..read]); - read_size = read_size + read; + read_size += read; debug!("{}: Total read: {} bytes", self.registry, read_size); if read == 0 { @@ -117,7 +117,7 @@ impl EppConnection { /// receieved to the request pub async fn transact(&mut self, content: &str) -> Result> { debug!("{}: request: {}", self.registry, content); - self.send_epp_request(&content).await?; + self.send_epp_request(content).await?; let response = self.get_epp_response().await?; debug!("{}: response: {}", self.registry, response); @@ -149,8 +149,7 @@ pub async fn epp_connect(registry_creds: &EppClientConnection) -> Result Result EppObject { pub fn build(data: T) -> EppObject { EppObject { // xml: None, - data: data, + data, xmlns: EPP_XMLNS.to_string(), xmlns_xsi: EPP_XMLNS_XSI.to_string(), xsi_schema_location: EPP_XSI_SCHEMA_LOCATION.to_string(), diff --git a/epp-client/src/epp/object/data.rs b/epp-client/src/epp/object/data.rs index edffbed..874e40d 100644 --- a/epp-client/src/epp/object/data.rs +++ b/epp-client/src/epp/object/data.rs @@ -106,7 +106,7 @@ impl Period { pub fn new(length: u16) -> Period { Period { unit: "y".to_string(), - length: length, + length, } } @@ -216,7 +216,7 @@ impl Address { .collect::>(); Address { - street: street, + street, city: city.to_string_value(), province: province.to_string_value(), postal_code: postal_code.to_string_value(), @@ -232,7 +232,7 @@ impl PostalInfo { info_type: info_type.to_string(), name: name.to_string_value(), organization: organization.to_string_value(), - address: address, + address, } } } diff --git a/epp-client/src/epp/request.rs b/epp-client/src/epp/request.rs index b4dae59..7993f50 100644 --- a/epp-client/src/epp/request.rs +++ b/epp-client/src/epp/request.rs @@ -61,7 +61,7 @@ impl Command { /// Creates a new <command> tag for an EPP document pub fn new(command: T, client_tr_id: &str) -> Command { Command { - command: command, + command, extension: None, client_tr_id: client_tr_id.to_string_value(), } @@ -72,7 +72,7 @@ impl CommandWithExtension { /// Creates a new <command> tag for an EPP document with a containing <extension> tag pub fn build(command: T, ext: E, client_tr_id: &str) -> CommandWithExtension { CommandWithExtension { - command: command, + command, extension: Some(Extension { data: ext }), client_tr_id: client_tr_id.to_string_value(), } @@ -122,14 +122,9 @@ impl EppLogin { ext_uris: &Option>, client_tr_id: &str, ) -> EppLogin { - let ext_uris = match ext_uris { - Some(uris) => Some( - uris.iter() + let ext_uris = ext_uris.as_ref().map(|uris| uris.iter() .map(|u| u.to_string_value()) - .collect::>(), - ), - None => None, - }; + .collect::>()); let login = Login { username: username.to_string_value(), @@ -144,7 +139,7 @@ impl EppLogin { EPP_CONTACT_XMLNS.to_string_value(), EPP_DOMAIN_XMLNS.to_string_value(), ], - svc_ext: Some(ServiceExtension { ext_uris: ext_uris }), + svc_ext: Some(ServiceExtension { ext_uris }), }, }; diff --git a/epp-client/src/epp/request/contact/check.rs b/epp-client/src/epp/request/contact/check.rs index cba964b..497e5c3 100644 --- a/epp-client/src/epp/request/contact/check.rs +++ b/epp-client/src/epp/request/contact/check.rs @@ -69,7 +69,7 @@ impl EppContactCheck { let contact_check = ContactCheck { list: ContactList { xmlns: EPP_CONTACT_XMLNS.to_string(), - contact_ids: contact_ids, + contact_ids, }, }; diff --git a/epp-client/src/epp/request/contact/create.rs b/epp-client/src/epp/request/contact/create.rs index 9c2f0fc..4129571 100644 --- a/epp-client/src/epp/request/contact/create.rs +++ b/epp-client/src/epp/request/contact/create.rs @@ -99,8 +99,8 @@ impl EppContactCreate { contact: Contact { xmlns: EPP_CONTACT_XMLNS.to_string(), id: id.to_string_value(), - postal_info: postal_info, - voice: voice, + postal_info, + voice, fax: None, email: email.to_string_value(), auth_info: data::AuthInfo::new(auth_password), diff --git a/epp-client/src/epp/request/contact/update.rs b/epp-client/src/epp/request/contact/update.rs index 5ef0030..e707ca1 100644 --- a/epp-client/src/epp/request/contact/update.rs +++ b/epp-client/src/epp/request/contact/update.rs @@ -151,7 +151,7 @@ impl EppContactUpdate { email: Some(res_data.info_data.email.clone()), postal_info: Some(res_data.info_data.postal_info.clone()), voice: Some(res_data.info_data.voice.clone()), - fax: res_data.info_data.fax.clone(), + fax: res_data.info_data.fax, auth_info: None, }); Ok(()) diff --git a/epp-client/src/epp/request/domain/check.rs b/epp-client/src/epp/request/domain/check.rs index 45f7db1..8d4fdf3 100644 --- a/epp-client/src/epp/request/domain/check.rs +++ b/epp-client/src/epp/request/domain/check.rs @@ -69,7 +69,7 @@ impl EppDomainCheck { let domain_check = DomainCheck { list: DomainList { xmlns: EPP_DOMAIN_XMLNS.to_string(), - domains: domains, + domains, }, }; diff --git a/epp-client/src/epp/request/domain/rgp/report.rs b/epp-client/src/epp/request/domain/rgp/report.rs index 7060643..790868c 100644 --- a/epp-client/src/epp/request/domain/rgp/report.rs +++ b/epp-client/src/epp/request/domain/rgp/report.rs @@ -161,7 +161,7 @@ impl EppDomainRgpRestoreReport { .to_rfc3339_opts(SecondsFormat::AutoSi, true) .to_string_value(), restore_reason: restore_reason.to_string_value(), - statements: statements, + statements, other: other.to_string_value(), }, }, diff --git a/epp-client/src/epp/request/host/check.rs b/epp-client/src/epp/request/host/check.rs index 2d999b9..7b3e83a 100644 --- a/epp-client/src/epp/request/host/check.rs +++ b/epp-client/src/epp/request/host/check.rs @@ -69,7 +69,7 @@ impl EppHostCheck { let host_check = HostCheck { list: HostList { xmlns: EPP_HOST_XMLNS.to_string(), - hosts: hosts, + hosts, }, }; diff --git a/epp-client/src/epp/response.rs b/epp-client/src/epp/response.rs index f96c6b0..37043af 100644 --- a/epp-client/src/epp/response.rs +++ b/epp-client/src/epp/response.rs @@ -261,14 +261,14 @@ impl CommandResponseWithExtension { /// Returns the data under the corresponding <resData> from the EPP XML pub fn res_data(&self) -> Option<&T> { match &self.res_data { - Some(res_data) => Some(&res_data), + Some(res_data) => Some(res_data), None => None, } } /// Returns the data under the corresponding from the EPP XML pub fn message_queue(&self) -> Option<&MessageQueue> { match &self.message_queue { - Some(queue) => Some(&queue), + Some(queue) => Some(queue), None => None, } } diff --git a/epp-client/src/epp/xml/quick_xml.rs b/epp-client/src/epp/xml/quick_xml.rs index b3892a5..f554103 100644 --- a/epp-client/src/epp/xml/quick_xml.rs +++ b/epp-client/src/epp/xml/quick_xml.rs @@ -25,7 +25,7 @@ impl EppXml for EppObject Ok(v) => v, Err(e) => { return Err(error::Error::EppDeserializationError( - format!("epp-client Deserialization Error: {}", e).to_string(), + format!("epp-client Deserialization Error: {}", e), )) } }; diff --git a/epp-client/src/error.rs b/epp-client/src/error.rs index a0084a3..8f4d5b3 100644 --- a/epp-client/src/error.rs +++ b/epp-client/src/error.rs @@ -34,7 +34,7 @@ impl Display for Error { impl From> for Error { fn from(e: std::boxed::Box) -> Self { - Self::Other(format!("{:?}", e).to_string()) + Self::Other(format!("{:?}", e)) } } diff --git a/epp-client/src/tests/mod.rs b/epp-client/src/tests/mod.rs index bff0da3..57d9bed 100644 --- a/epp-client/src/tests/mod.rs +++ b/epp-client/src/tests/mod.rs @@ -17,8 +17,8 @@ fn get_xml(path: &str) -> Result> { let mut buf = String::new(); f.read_to_string(&mut buf)?; - if buf.len() > 0 { - let mat = Regex::new(r"\?>").unwrap().find(&buf.as_str()).unwrap(); + if !buf.is_empty() { + let mat = Regex::new(r"\?>").unwrap().find(buf.as_str()).unwrap(); let start = mat.end(); buf = format!( "{}\r\n{}",