Skip to content

Commit c1481d3

Browse files
crapStoneenarxbot
authored andcommitted
fix clippy and format warnings
1 parent 21cdf26 commit c1481d3

File tree

5 files changed

+22
-31
lines changed

5 files changed

+22
-31
lines changed

ciborium/src/de/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ where
348348

349349
let mut segments = self.decoder.text(len);
350350
while let Some(mut segment) = segments.pull()? {
351-
while let Some(chunk) = segment.pull(&mut self.scratch)? {
351+
while let Some(chunk) = segment.pull(self.scratch)? {
352352
buffer.push_str(chunk);
353353
}
354354
}
@@ -389,7 +389,7 @@ where
389389

390390
let mut segments = self.decoder.bytes(len);
391391
while let Some(mut segment) = segments.pull()? {
392-
while let Some(chunk) = segment.pull(&mut self.scratch)? {
392+
while let Some(chunk) = segment.pull(self.scratch)? {
393393
buffer.extend_from_slice(chunk);
394394
}
395395
}

ciborium/src/value/canonical.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn cmp_value(v1: &Value, v2: &Value) -> Ordering {
4949
(Bool(s), Bool(o)) => s.cmp(o),
5050
(Null, Null) => Ordering::Equal,
5151
(Tag(t, v), Tag(ot, ov)) => match Value::from(*t).partial_cmp(&Value::from(*ot)) {
52-
Some(Ordering::Equal) | None => match v.partial_cmp(&ov) {
52+
Some(Ordering::Equal) | None => match v.partial_cmp(ov) {
5353
Some(x) => x,
5454
None => serialized_canonical_cmp(v1, v2),
5555
},
@@ -80,9 +80,9 @@ impl From<Value> for CanonicalValue {
8080
}
8181
}
8282

83-
impl Into<Value> for CanonicalValue {
84-
fn into(self) -> Value {
85-
self.0
83+
impl From<CanonicalValue> for Value {
84+
fn from(v: CanonicalValue) -> Self {
85+
v.0
8686
}
8787
}
8888

ciborium/src/value/integer.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl Integer {
3939
/// This is called `canonical` as it is only used for canonically comparing two
4040
/// values. It shouldn't be used in any other context.
4141
fn canonical_len(&self) -> usize {
42-
let x = *&self.0;
42+
let x = self.0;
4343

4444
if let Ok(x) = u8::try_from(x) {
4545
if x < 24 {
@@ -53,17 +53,11 @@ impl Integer {
5353
} else {
5454
2
5555
}
56-
} else if let Ok(_) = u16::try_from(x) {
56+
} else if u16::try_from(x).is_ok() || i16::try_from(x).is_ok() {
5757
3
58-
} else if let Ok(_) = i16::try_from(x) {
59-
3
60-
} else if let Ok(_) = u32::try_from(x) {
61-
5
62-
} else if let Ok(_) = i32::try_from(x) {
58+
} else if u32::try_from(x).is_ok() || i32::try_from(x).is_ok() {
6359
5
64-
} else if let Ok(_) = u64::try_from(x) {
65-
9
66-
} else if let Ok(_) = i64::try_from(x) {
60+
} else if u64::try_from(x).is_ok() || i64::try_from(x).is_ok() {
6761
9
6862
} else {
6963
// Ciborium serializes u128/i128 as BigPos if they don't fit in 64 bits.
@@ -79,12 +73,8 @@ impl Integer {
7973
Ordering::Equal => {
8074
// Negative numbers are higher in byte-order than positive numbers.
8175
match (self.0.is_negative(), other.0.is_negative()) {
82-
(false, true) => {
83-
Ordering::Less
84-
}
85-
(true, false) => {
86-
Ordering::Greater
87-
}
76+
(false, true) => Ordering::Less,
77+
(true, false) => Ordering::Greater,
8878
(true, true) => {
8979
// For negative numbers the byte order puts numbers closer to 0 which
9080
// are lexically higher, lower. So -1 < -2 when sorting by be_bytes().
@@ -94,11 +84,9 @@ impl Integer {
9484
Ordering::Greater => Ordering::Less,
9585
}
9686
}
97-
(_, _) => {
98-
self.0.cmp(&other.0)
99-
}
87+
(_, _) => self.0.cmp(&other.0),
10088
}
101-
},
89+
}
10290
x => x,
10391
}
10492
}

ciborium/src/value/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
//! A dynamic CBOR value
44
5-
mod integer;
65
mod canonical;
6+
mod integer;
77

88
mod de;
99
mod error;
1010
mod ser;
1111

12+
pub use canonical::CanonicalValue;
1213
pub use error::Error;
1314
pub use integer::Integer;
14-
pub use canonical::CanonicalValue;
1515

1616
use alloc::{boxed::Box, string::String, vec::Vec};
1717

ciborium/tests/canonical.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
extern crate std;
44

5-
use std::collections::BTreeMap;
65
use ciborium::cbor;
7-
use ciborium::value::{ CanonicalValue, };
6+
use ciborium::value::CanonicalValue;
87
use rand::prelude::*;
8+
use std::collections::BTreeMap;
99

1010
macro_rules! cval {
1111
($x:expr) => {
@@ -56,7 +56,10 @@ fn map() {
5656
let mut bytes1 = Vec::new();
5757
ciborium::ser::into_writer(&map, &mut bytes1).unwrap();
5858

59-
assert_eq!(hex::encode(&bytes1), "a80a002001f402186403617a048120056261610681186407");
59+
assert_eq!(
60+
hex::encode(&bytes1),
61+
"a80a002001f402186403617a048120056261610681186407"
62+
);
6063
}
6164

6265
#[test]

0 commit comments

Comments
 (0)