Skip to content

Commit ea97df0

Browse files
committed
clippy fixes
Signed-off-by: Dave Huseby <[email protected]>
1 parent a324893 commit ea97df0

File tree

4 files changed

+48
-52
lines changed

4 files changed

+48
-52
lines changed

src/attrid.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub enum AttrId {
2828
impl AttrId {
2929
/// Get the code for the attribute id
3030
pub fn code(&self) -> u8 {
31-
self.clone().into()
31+
(*self).into()
3232
}
3333

3434
/// Convert the attribute id to &str
@@ -45,9 +45,9 @@ impl AttrId {
4545
}
4646
}
4747

48-
impl Into<u8> for AttrId {
49-
fn into(self) -> u8 {
50-
self as u8
48+
impl From<AttrId> for u8 {
49+
fn from(val: AttrId) -> Self {
50+
val as u8
5151
}
5252
}
5353

@@ -68,9 +68,9 @@ impl TryFrom<u8> for AttrId {
6868
}
6969
}
7070

71-
impl Into<Vec<u8>> for AttrId {
72-
fn into(self) -> Vec<u8> {
73-
self.code().encode_into()
71+
impl From<AttrId> for Vec<u8> {
72+
fn from(val: AttrId) -> Self {
73+
val.code().encode_into()
7474
}
7575
}
7676

src/ms.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,19 @@ impl EncodingInfo for Multisig {
7777
}
7878
}
7979

80-
impl Into<Vec<u8>> for Multisig {
81-
fn into(self) -> Vec<u8> {
80+
impl From<Multisig> for Vec<u8> {
81+
fn from(val: Multisig) -> Self {
8282
let mut v = Vec::default();
8383
// add in the sigil
8484
v.append(&mut SIGIL.into());
8585
// add in the signature codec
86-
v.append(&mut self.codec.into());
86+
v.append(&mut val.codec.into());
8787
// add in the message
88-
v.append(&mut Varbytes(self.message.clone()).into());
88+
v.append(&mut Varbytes(val.message.clone()).into());
8989
// add in the number of attributes
90-
v.append(&mut Varuint(self.attributes.len()).into());
90+
v.append(&mut Varuint(val.attributes.len()).into());
9191
// add in the attributes
92-
self.attributes.iter().for_each(|(id, attr)| {
92+
val.attributes.iter().for_each(|(id, attr)| {
9393
v.append(&mut (*id).into());
9494
v.append(&mut Varbytes(attr.clone()).into());
9595
});
@@ -167,7 +167,7 @@ impl fmt::Debug for Multisig {
167167
"{:?} - {:?} - {}",
168168
SIGIL,
169169
self.codec(),
170-
if self.message.len() > 0 {
170+
if !self.message.is_empty() {
171171
"Combined"
172172
} else {
173173
"Detached"
@@ -405,7 +405,7 @@ impl Builder {
405405

406406
fn with_attribute(mut self, attr: AttrId, data: &Vec<u8>) -> Self {
407407
let mut attributes = self.attributes.unwrap_or_default();
408-
attributes.insert(attr, data.clone());
408+
attributes.insert(attr, data.to_owned());
409409
self.attributes = Some(attributes);
410410
self
411411
}
@@ -457,7 +457,7 @@ impl Builder {
457457
pub fn try_build_encoded(self) -> Result<EncodedMultisig, Error> {
458458
Ok(BaseEncoded::new(
459459
self.base_encoding
460-
.unwrap_or_else(|| Multisig::preferred_encoding()),
460+
.unwrap_or_else(Multisig::preferred_encoding),
461461
self.try_build()?,
462462
))
463463
}

src/serde/de.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,28 @@ impl<'de> Deserialize<'de> for AttrId {
3030
where
3131
E: Error,
3232
{
33-
Ok(AttrId::try_from(c).map_err(|e| Error::custom(e.to_string()))?)
33+
AttrId::try_from(c).map_err(|e| Error::custom(e.to_string()))
3434
}
3535

3636
fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
3737
where
3838
E: Error,
3939
{
40-
Ok(AttrId::try_from(s).map_err(|e| Error::custom(e.to_string()))?)
40+
AttrId::try_from(s).map_err(|e| Error::custom(e.to_string()))
4141
}
4242

4343
fn visit_borrowed_str<E>(self, s: &'de str) -> Result<Self::Value, E>
4444
where
4545
E: Error,
4646
{
47-
Ok(AttrId::try_from(s).map_err(|e| Error::custom(e.to_string()))?)
47+
AttrId::try_from(s).map_err(|e| Error::custom(e.to_string()))
4848
}
4949

5050
fn visit_string<E>(self, s: String) -> Result<Self::Value, E>
5151
where
5252
E: Error,
5353
{
54-
Ok(AttrId::try_from(s.as_str()).map_err(|e| Error::custom(e.to_string()))?)
54+
AttrId::try_from(s.as_str()).map_err(|e| Error::custom(e.to_string()))
5555
}
5656
}
5757

@@ -65,7 +65,7 @@ impl<'de> Deserialize<'de> for Multisig {
6565
where
6666
D: Deserializer<'de>,
6767
{
68-
const FIELDS: &'static [&'static str] = &["codec", "message", "attributes"];
68+
const FIELDS: &[&str] = &["codec", "message", "attributes"];
6969

7070
#[derive(Deserialize)]
7171
#[serde(field_identifier, rename_all = "lowercase")]

src/views/bls12381.rs

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub enum SchemeTypeId {
3737
impl SchemeTypeId {
3838
/// Get the code for the attribute id
3939
pub fn code(&self) -> u8 {
40-
self.clone().into()
40+
(*self).into()
4141
}
4242

4343
/// Convert the attribute id to &str
@@ -50,9 +50,9 @@ impl SchemeTypeId {
5050
}
5151
}
5252

53-
impl Into<u8> for SchemeTypeId {
54-
fn into(self) -> u8 {
55-
self as u8
53+
impl From<SchemeTypeId> for u8 {
54+
fn from(val: SchemeTypeId) -> Self {
55+
val as u8
5656
}
5757
}
5858

@@ -69,9 +69,9 @@ impl TryFrom<u8> for SchemeTypeId {
6969
}
7070
}
7171

72-
impl Into<SignatureSchemes> for SchemeTypeId {
73-
fn into(self) -> SignatureSchemes {
74-
match self {
72+
impl From<SchemeTypeId> for SignatureSchemes {
73+
fn from(val: SchemeTypeId) -> Self {
74+
match val {
7575
SchemeTypeId::Basic => SignatureSchemes::Basic,
7676
SchemeTypeId::MessageAugmentation => SignatureSchemes::MessageAugmentation,
7777
SchemeTypeId::ProofOfPossession => SignatureSchemes::ProofOfPossession,
@@ -115,9 +115,9 @@ where
115115
}
116116
}
117117

118-
impl Into<Vec<u8>> for SchemeTypeId {
119-
fn into(self) -> Vec<u8> {
120-
self.code().encode_into()
118+
impl From<SchemeTypeId> for Vec<u8> {
119+
fn from(val: SchemeTypeId) -> Self {
120+
val.code().encode_into()
121121
}
122122
}
123123

@@ -167,13 +167,13 @@ pub struct SigCombined(
167167
pub Vec<u8>,
168168
);
169169

170-
impl Into<Vec<u8>> for SigCombined {
171-
fn into(self) -> Vec<u8> {
170+
impl From<SigCombined> for Vec<u8> {
171+
fn from(val: SigCombined) -> Self {
172172
let mut v = Vec::default();
173173
// add in the signature type id
174-
v.append(&mut self.0.into());
174+
v.append(&mut val.0.into());
175175
// add in the signature bytes
176-
v.append(&mut Varbytes(self.1.clone()).into());
176+
v.append(&mut Varbytes(val.1.clone()).into());
177177
v
178178
}
179179
}
@@ -214,19 +214,19 @@ pub struct SigShare(
214214
pub Vec<u8>,
215215
);
216216

217-
impl Into<Vec<u8>> for SigShare {
218-
fn into(self) -> Vec<u8> {
217+
impl From<SigShare> for Vec<u8> {
218+
fn from(val: SigShare) -> Self {
219219
let mut v = Vec::default();
220220
// add in the share identifier
221-
v.append(&mut Varuint(self.0).into());
221+
v.append(&mut Varuint(val.0).into());
222222
// add in the share threshold
223-
v.append(&mut Varuint(self.1).into());
223+
v.append(&mut Varuint(val.1).into());
224224
// add in the share limit
225-
v.append(&mut Varuint(self.2).into());
225+
v.append(&mut Varuint(val.2).into());
226226
// add in the share type id
227-
v.append(&mut self.3.into());
227+
v.append(&mut val.3.into());
228228
// add in the share data
229-
v.append(&mut Varbytes(self.4.clone()).into());
229+
v.append(&mut Varbytes(val.4.clone()).into());
230230
v
231231
}
232232
}
@@ -270,13 +270,13 @@ impl<'a> TryDecodeFrom<'a> for SigShare {
270270
#[derive(Clone, Default)]
271271
pub(crate) struct ThresholdData(pub(crate) BTreeMap<u8, SigShare>);
272272

273-
impl Into<Vec<u8>> for ThresholdData {
274-
fn into(self) -> Vec<u8> {
273+
impl From<ThresholdData> for Vec<u8> {
274+
fn from(val: ThresholdData) -> Self {
275275
let mut v = Vec::default();
276276
// add in the number of sig shares
277-
v.append(&mut Varuint(self.0.len()).into());
277+
v.append(&mut Varuint(val.0.len()).into());
278278
// add in the sig shares
279-
self.0.iter().for_each(|(_, share)| {
279+
val.0.iter().for_each(|(_, share)| {
280280
v.append(&mut share.clone().into());
281281
});
282282
v
@@ -607,11 +607,7 @@ impl<'a> ThresholdView for View<'a> {
607607
match av.payload_encoding() {
608608
Ok(encoding) => Some(encoding),
609609
Err(_) => {
610-
if let Some(encoding) = encoding {
611-
Some(encoding)
612-
} else {
613-
None
614-
}
610+
encoding
615611
}
616612
}
617613
};
@@ -737,7 +733,7 @@ impl<'a> ThresholdView for View<'a> {
737733
builder.try_build()
738734
}
739735
}
740-
_ => return Err(Error::UnsupportedAlgorithm(self.ms.codec.to_string())),
736+
_ => Err(Error::UnsupportedAlgorithm(self.ms.codec.to_string())),
741737
}
742738
}
743739
}

0 commit comments

Comments
 (0)