diff --git a/src/attrid.rs b/src/attrid.rs index 9dd6468..ea76b6a 100644 --- a/src/attrid.rs +++ b/src/attrid.rs @@ -28,7 +28,7 @@ pub enum AttrId { impl AttrId { /// Get the code for the attribute id pub fn code(&self) -> u8 { - self.clone().into() + (*self).into() } /// Convert the attribute id to &str @@ -45,9 +45,9 @@ impl AttrId { } } -impl Into for AttrId { - fn into(self) -> u8 { - self as u8 +impl From for u8 { + fn from(val: AttrId) -> Self { + val as u8 } } @@ -68,9 +68,9 @@ impl TryFrom for AttrId { } } -impl Into> for AttrId { - fn into(self) -> Vec { - self.code().encode_into() +impl From for Vec { + fn from(val: AttrId) -> Self { + val.code().encode_into() } } diff --git a/src/ms.rs b/src/ms.rs index 71ef355..1b4beea 100644 --- a/src/ms.rs +++ b/src/ms.rs @@ -77,19 +77,19 @@ impl EncodingInfo for Multisig { } } -impl Into> for Multisig { - fn into(self) -> Vec { +impl From for Vec { + fn from(val: Multisig) -> Self { let mut v = Vec::default(); // add in the sigil v.append(&mut SIGIL.into()); // add in the signature codec - v.append(&mut self.codec.into()); + v.append(&mut val.codec.into()); // add in the message - v.append(&mut Varbytes(self.message.clone()).into()); + v.append(&mut Varbytes(val.message.clone()).into()); // add in the number of attributes - v.append(&mut Varuint(self.attributes.len()).into()); + v.append(&mut Varuint(val.attributes.len()).into()); // add in the attributes - self.attributes.iter().for_each(|(id, attr)| { + val.attributes.iter().for_each(|(id, attr)| { v.append(&mut (*id).into()); v.append(&mut Varbytes(attr.clone()).into()); }); @@ -167,7 +167,7 @@ impl fmt::Debug for Multisig { "{:?} - {:?} - {}", SIGIL, self.codec(), - if self.message.len() > 0 { + if !self.message.is_empty() { "Combined" } else { "Detached" @@ -405,7 +405,7 @@ impl Builder { fn with_attribute(mut self, attr: AttrId, data: &Vec) -> Self { let mut attributes = self.attributes.unwrap_or_default(); - attributes.insert(attr, data.clone()); + attributes.insert(attr, data.to_owned()); self.attributes = Some(attributes); self } @@ -457,7 +457,7 @@ impl Builder { pub fn try_build_encoded(self) -> Result { Ok(BaseEncoded::new( self.base_encoding - .unwrap_or_else(|| Multisig::preferred_encoding()), + .unwrap_or_else(Multisig::preferred_encoding), self.try_build()?, )) } diff --git a/src/serde/de.rs b/src/serde/de.rs index 5c7f13c..3a5ef69 100644 --- a/src/serde/de.rs +++ b/src/serde/de.rs @@ -30,28 +30,28 @@ impl<'de> Deserialize<'de> for AttrId { where E: Error, { - Ok(AttrId::try_from(c).map_err(|e| Error::custom(e.to_string()))?) + AttrId::try_from(c).map_err(|e| Error::custom(e.to_string())) } fn visit_str(self, s: &str) -> Result where E: Error, { - Ok(AttrId::try_from(s).map_err(|e| Error::custom(e.to_string()))?) + AttrId::try_from(s).map_err(|e| Error::custom(e.to_string())) } fn visit_borrowed_str(self, s: &'de str) -> Result where E: Error, { - Ok(AttrId::try_from(s).map_err(|e| Error::custom(e.to_string()))?) + AttrId::try_from(s).map_err(|e| Error::custom(e.to_string())) } fn visit_string(self, s: String) -> Result where E: Error, { - Ok(AttrId::try_from(s.as_str()).map_err(|e| Error::custom(e.to_string()))?) + AttrId::try_from(s.as_str()).map_err(|e| Error::custom(e.to_string())) } } @@ -65,7 +65,7 @@ impl<'de> Deserialize<'de> for Multisig { where D: Deserializer<'de>, { - const FIELDS: &'static [&'static str] = &["codec", "message", "attributes"]; + const FIELDS: &[&str] = &["codec", "message", "attributes"]; #[derive(Deserialize)] #[serde(field_identifier, rename_all = "lowercase")] diff --git a/src/views/bls12381.rs b/src/views/bls12381.rs index 2dd643c..ef984c2 100644 --- a/src/views/bls12381.rs +++ b/src/views/bls12381.rs @@ -37,7 +37,7 @@ pub enum SchemeTypeId { impl SchemeTypeId { /// Get the code for the attribute id pub fn code(&self) -> u8 { - self.clone().into() + (*self).into() } /// Convert the attribute id to &str @@ -50,9 +50,9 @@ impl SchemeTypeId { } } -impl Into for SchemeTypeId { - fn into(self) -> u8 { - self as u8 +impl From for u8 { + fn from(val: SchemeTypeId) -> Self { + val as u8 } } @@ -69,9 +69,9 @@ impl TryFrom for SchemeTypeId { } } -impl Into for SchemeTypeId { - fn into(self) -> SignatureSchemes { - match self { +impl From for SignatureSchemes { + fn from(val: SchemeTypeId) -> Self { + match val { SchemeTypeId::Basic => SignatureSchemes::Basic, SchemeTypeId::MessageAugmentation => SignatureSchemes::MessageAugmentation, SchemeTypeId::ProofOfPossession => SignatureSchemes::ProofOfPossession, @@ -115,9 +115,9 @@ where } } -impl Into> for SchemeTypeId { - fn into(self) -> Vec { - self.code().encode_into() +impl From for Vec { + fn from(val: SchemeTypeId) -> Self { + val.code().encode_into() } } @@ -167,13 +167,13 @@ pub struct SigCombined( pub Vec, ); -impl Into> for SigCombined { - fn into(self) -> Vec { +impl From for Vec { + fn from(val: SigCombined) -> Self { let mut v = Vec::default(); // add in the signature type id - v.append(&mut self.0.into()); + v.append(&mut val.0.into()); // add in the signature bytes - v.append(&mut Varbytes(self.1.clone()).into()); + v.append(&mut Varbytes(val.1.clone()).into()); v } } @@ -214,19 +214,19 @@ pub struct SigShare( pub Vec, ); -impl Into> for SigShare { - fn into(self) -> Vec { +impl From for Vec { + fn from(val: SigShare) -> Self { let mut v = Vec::default(); // add in the share identifier - v.append(&mut Varuint(self.0).into()); + v.append(&mut Varuint(val.0).into()); // add in the share threshold - v.append(&mut Varuint(self.1).into()); + v.append(&mut Varuint(val.1).into()); // add in the share limit - v.append(&mut Varuint(self.2).into()); + v.append(&mut Varuint(val.2).into()); // add in the share type id - v.append(&mut self.3.into()); + v.append(&mut val.3.into()); // add in the share data - v.append(&mut Varbytes(self.4.clone()).into()); + v.append(&mut Varbytes(val.4.clone()).into()); v } } @@ -270,13 +270,13 @@ impl<'a> TryDecodeFrom<'a> for SigShare { #[derive(Clone, Default)] pub(crate) struct ThresholdData(pub(crate) BTreeMap); -impl Into> for ThresholdData { - fn into(self) -> Vec { +impl From for Vec { + fn from(val: ThresholdData) -> Self { let mut v = Vec::default(); // add in the number of sig shares - v.append(&mut Varuint(self.0.len()).into()); + v.append(&mut Varuint(val.0.len()).into()); // add in the sig shares - self.0.iter().for_each(|(_, share)| { + val.0.iter().for_each(|(_, share)| { v.append(&mut share.clone().into()); }); v @@ -607,11 +607,7 @@ impl<'a> ThresholdView for View<'a> { match av.payload_encoding() { Ok(encoding) => Some(encoding), Err(_) => { - if let Some(encoding) = encoding { - Some(encoding) - } else { - None - } + encoding } } }; @@ -737,7 +733,7 @@ impl<'a> ThresholdView for View<'a> { builder.try_build() } } - _ => return Err(Error::UnsupportedAlgorithm(self.ms.codec.to_string())), + _ => Err(Error::UnsupportedAlgorithm(self.ms.codec.to_string())), } } }