diff --git a/lightning/src/onion_message/dns_resolution.rs b/lightning/src/onion_message/dns_resolution.rs index 6d9d4d61428..47d4bc09e04 100644 --- a/lightning/src/onion_message/dns_resolution.rs +++ b/lightning/src/onion_message/dns_resolution.rs @@ -211,9 +211,9 @@ pub struct HumanReadableName { impl HumanReadableName { /// Constructs a new [`HumanReadableName`] from the `user` and `domain` parts. See the /// struct-level documentation for more on the requirements on each. - pub fn new(user: &str, domain: &str) -> Result { + pub fn new(user: &str, domain: &str) -> Result { // First normalize domain and remove the optional trailing `.` - let domain = domain.strip_suffix(".").unwrap_or(domain); + let domain = domain.strip_suffix('.').unwrap_or(domain); if user.len() + domain.len() + REQUIRED_EXTRA_LEN > 255 { return Err(()); } @@ -233,24 +233,17 @@ impl HumanReadableName { let mut contents = [0; 255 - REQUIRED_EXTRA_LEN]; contents[..user.len()].copy_from_slice(user.as_bytes()); contents[user.len()..user.len() + domain.len()].copy_from_slice(domain.as_bytes()); - Ok(HumanReadableName { - contents, - user_len: user.len() as u8, - domain_len: domain.len() as u8, - }) + Ok(Self { contents, user_len: user.len() as u8, domain_len: domain.len() as u8 }) } /// Constructs a new [`HumanReadableName`] from the standard encoding - `user`@`domain`. /// /// If `user` includes the standard BIP 353 ₿ prefix it is automatically removed as required by /// BIP 353. - pub fn from_encoded(encoded: &str) -> Result { - if let Some((user, domain)) = encoded.strip_prefix('₿').unwrap_or(encoded).split_once("@") - { - Self::new(user, domain) - } else { - Err(()) - } + pub fn from_encoded(encoded: &str) -> Result { + let encoded = encoded.strip_prefix('₿').unwrap_or(encoded); + let (user, domain) = encoded.split_once('@').ok_or(())?; + Self::new(user, domain) } /// Gets the `user` part of this Human Readable Name @@ -438,9 +431,9 @@ impl OMNameResolver { &self, msg: DNSSECProof, context: DNSResolverContext, ) -> Option<(Vec<(HumanReadableName, PaymentId)>, Offer)> { let (completed_requests, uri) = self.handle_dnssec_proof_for_uri(msg, context)?; - if let Some((_onchain, params)) = uri.split_once("?") { - for param in params.split("&") { - let (k, v) = if let Some(split) = param.split_once("=") { + if let Some((_onchain, params)) = uri.split_once('?') { + for param in params.split('&') { + let (k, v) = if let Some(split) = param.split_once('=') { split } else { continue;