Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Oct 9, 2024
1 parent 9cc3fc2 commit 1e4e9c0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
26 changes: 13 additions & 13 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<'de> Deserializer<'de> {

fn raw_deserialize_u16(&mut self, major: u8) -> Result<u16> {
let number = self.raw_deserialize_u32(major)?;
if number <= u16::max_value() as u32 {
if number <= u16::MAX as u32 {
Ok(number as u16)
} else {
Err(Error::DeserializeBadU16)
Expand Down Expand Up @@ -445,15 +445,15 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
match self.peek_major()? {
MAJOR_POSINT => {
let raw_u8 = self.raw_deserialize_u8(0)?;
if raw_u8 <= i8::max_value() as u8 {
if raw_u8 <= i8::MAX as u8 {
visitor.visit_i8(raw_u8 as i8)
} else {
Err(Error::DeserializeBadI8)
}
}
MAJOR_NEGINT => {
let raw_u8 = self.raw_deserialize_u8(1)?;
// if raw_u8 <= 1 + i8::max_value() as u8 {
// if raw_u8 <= 1 + i8::MAX as u8 {
if raw_u8 <= 128 {
visitor.visit_i8(-1 - (raw_u8 as i16) as i8)
} else {
Expand All @@ -471,15 +471,15 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
match self.peek_major()? {
MAJOR_POSINT => {
let raw = self.raw_deserialize_u16(0)?;
if raw <= i16::max_value() as u16 {
if raw <= i16::MAX as u16 {
visitor.visit_i16(raw as i16)
} else {
Err(Error::DeserializeBadI16)
}
}
MAJOR_NEGINT => {
let raw = self.raw_deserialize_u16(1)?;
if raw <= i16::max_value() as u16 {
if raw <= i16::MAX as u16 {
visitor.visit_i16(-1 - (raw as i16))
} else {
Err(Error::DeserializeBadI16)
Expand All @@ -497,7 +497,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
// TODO: figure out if this is BAAAAD for size or speed
major @ 0..=1 => {
let raw = self.raw_deserialize_u32(major)?;
if raw <= i32::max_value() as u32 {
if raw <= i32::MAX as u32 {
if major == MAJOR_POSINT {
visitor.visit_i32(raw as i32)
} else {
Expand All @@ -519,7 +519,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
// TODO: figure out if this is BAAAAD for size or speed
major @ 0..=1 => {
let raw = self.raw_deserialize_u64(major)?;
if raw <= i64::max_value() as u64 {
if raw <= i64::MAX as u64 {
if major == MAJOR_POSINT {
visitor.visit_i64(raw as i64)
} else {
Expand Down Expand Up @@ -562,7 +562,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
V: Visitor<'de>,
{
let raw = self.raw_deserialize_u64(MAJOR_POSINT)?;
visitor.visit_u64(raw as u64)
visitor.visit_u64(raw)
}

fn deserialize_f32<V>(self, _visitor: V) -> Result<V::Value>
Expand Down Expand Up @@ -971,7 +971,7 @@ mod tests {
fn de_i16() {
let mut buf = [0u8; 64];

for number in i16::min_value()..=i16::max_value() {
for number in i16::min_value()..=i16::MAX {
println!("testing {}", number);
let _n = cbor_serialize(&number, &mut buf).unwrap();
let de: i16 = from_bytes(&buf).unwrap();
Expand All @@ -983,14 +983,14 @@ mod tests {
fn de_u32() {
let mut buf = [0u8; 64];

for number in 0..=3 * (u16::max_value() as u32) {
for number in 0..=3 * (u16::MAX as u32) {
println!("testing {}", number);
let _n = cbor_serialize(&number, &mut buf).unwrap();
let de: u32 = from_bytes(&buf).unwrap();
assert_eq!(de, number);
}

for number in (u32::max_value() - u16::max_value() as u32)..=u32::max_value() {
for number in (u32::MAX - u16::MAX as u32)..=u32::MAX {
println!("testing {}", number);
let _n = cbor_serialize(&number, &mut buf).unwrap();
let de: u32 = from_bytes(&buf).unwrap();
Expand Down Expand Up @@ -1033,14 +1033,14 @@ mod tests {
let de: i32 = from_bytes(ser).unwrap();
assert_eq!(de, number);

for number in (3 * i16::min_value() as i32)..=3 * (i16::max_value() as i32) {
for number in (3 * i16::min_value() as i32)..=3 * (i16::MAX as i32) {
println!("testing {}", number);
let ser = cbor_serialize(&number, &mut buf).unwrap();
let de: i32 = from_bytes(ser).unwrap();
assert_eq!(de, number);
}

for number in (i32::max_value() - i16::max_value() as i32)..=i32::max_value() {
for number in (i32::MAX - i16::MAX as i32)..=i32::MAX {
println!("testing {}", number);
let ser = cbor_serialize(&number, &mut buf).unwrap();
let de: i32 = from_bytes(ser).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use ser::Writer;
/// Serialize an object to a `Writer`
///
/// Returns the amount of bytes written to the writer
pub fn cbor_serialize_to<'a, T: ?Sized + serde::Serialize, W: Writer>(
pub fn cbor_serialize_to<T: ?Sized + serde::Serialize, W: Writer>(
object: &T,
writer: W,
) -> Result<usize> {
Expand Down
12 changes: 6 additions & 6 deletions src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub trait Writer {

impl<'a> Writer for &'a mut [u8] {
type Error = Error;
fn write_all<'b>(&'b mut self, buf: &[u8]) -> Result<()> {
fn write_all(&mut self, buf: &[u8]) -> Result<()> {
let l = buf.len();
if self.len() < l {
// This buffer will not fit in our slice
Expand Down Expand Up @@ -121,7 +121,7 @@ impl<W: Writer> Serializer<W> {

#[inline]
fn write_u16(&mut self, major: u8, value: u16) -> Result<()> {
if value <= u16::from(u8::max_value()) {
if value <= u16::from(u8::MAX) {
self.write_u8(major, value as u8)
} else {
let mut buf = [major << MAJOR_OFFSET | 25, 0, 0];
Expand All @@ -132,7 +132,7 @@ impl<W: Writer> Serializer<W> {

#[inline]
fn write_u32(&mut self, major: u8, value: u32) -> Result<()> {
if value <= u32::from(u16::max_value()) {
if value <= u32::from(u16::MAX) {
self.write_u16(major, value as u16)
} else {
let mut buf = [major << MAJOR_OFFSET | 26, 0, 0, 0, 0];
Expand All @@ -143,7 +143,7 @@ impl<W: Writer> Serializer<W> {

#[inline]
fn write_u64(&mut self, major: u8, value: u64) -> Result<()> {
if value <= u64::from(u32::max_value()) {
if value <= u64::from(u32::MAX) {
self.write_u32(major, value as u32)
} else {
let mut buf = [major << MAJOR_OFFSET | 27, 0, 0, 0, 0, 0, 0, 0, 0];
Expand Down Expand Up @@ -417,9 +417,9 @@ where
self.serialize_struct(name, len)
}

fn collect_str<T: ?Sized>(self, _value: &T) -> Result<Self::Ok>
fn collect_str<T>(self, _value: &T) -> Result<Self::Ok>
where
T: core::fmt::Display,
T: core::fmt::Display + ?Sized,
{
unreachable!()
}
Expand Down

0 comments on commit 1e4e9c0

Please sign in to comment.