diff --git a/Makefile b/Makefile index 71564d6b..e9a20547 100644 --- a/Makefile +++ b/Makefile @@ -10,4 +10,4 @@ wasmtest: cargo clean --target-dir target cargo build --tests --target wasm32-wasip1 --target-dir target wasmtime run target/wasm32-wasip1/debug/deps/simd_json*.wasm - wasmtime run --dir=. target/wasm32-wasip1/debug/deps/jsonchecker*.wasm + wasmtime run --dir=. target/wasm32-wasip1/debug/deps/jsonchecker*.wasm diff --git a/src/impls/neon/deser.rs b/src/impls/neon/deser.rs index 3782cf29..e2dc1aa3 100644 --- a/src/impls/neon/deser.rs +++ b/src/impls/neon/deser.rs @@ -168,12 +168,11 @@ pub(crate) fn parse_str<'invoke, 'de>( // within the unicode codepoint handling code. src_i += bs_dist as usize; dst_i += bs_dist as usize; - let (o, s) = if let Ok(r) = + let Ok((o, s)) = handle_unicode_codepoint(unsafe { src.get_kinda_unchecked(src_i..) }, unsafe { buffer.get_kinda_unchecked_mut(dst_i..) - }) { - r - } else { + }) + else { return Err(Deserializer::error_c(src_i, 'u', InvalidUnicodeCodepoint)); }; if o == 0 { diff --git a/src/impls/simd128/deser.rs b/src/impls/simd128/deser.rs index af77e16b..97a88701 100644 --- a/src/impls/simd128/deser.rs +++ b/src/impls/simd128/deser.rs @@ -136,12 +136,11 @@ pub(crate) fn parse_str<'invoke, 'de>( // within the unicode codepoint handling code. src_i += bs_dist as usize; dst_i += bs_dist as usize; - let (o, s) = if let Ok(r) = + let Ok((o, s)) = handle_unicode_codepoint(unsafe { src.get_kinda_unchecked(src_i..) }, unsafe { buffer.get_kinda_unchecked_mut(dst_i..) - }) { - r - } else { + }) + else { return Err(Deserializer::error_c(src_i, 'u', InvalidUnicodeCodepoint)); }; if o == 0 { diff --git a/src/impls/sse42/deser.rs b/src/impls/sse42/deser.rs index ebf21b57..2522091b 100644 --- a/src/impls/sse42/deser.rs +++ b/src/impls/sse42/deser.rs @@ -141,12 +141,10 @@ pub(crate) unsafe fn parse_str<'invoke, 'de>( // within the unicode codepoint handling code. src_i += bs_dist as usize; dst_i += bs_dist as usize; - let (o, s) = if let Ok(r) = handle_unicode_codepoint( + let Ok((o, s)) = handle_unicode_codepoint( src.get_kinda_unchecked(src_i..), buffer.get_kinda_unchecked_mut(dst_i..), - ) { - r - } else { + ) else { return Err(Deserializer::error_c(src_i, 'u', InvalidUnicodeCodepoint)); }; if o == 0 { diff --git a/src/lib.rs b/src/lib.rs index 592572ea..b069d557 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1029,16 +1029,14 @@ impl AlignedBuf { /// Creates a new buffer that is aligned with the simd register size #[must_use] pub fn with_capacity(capacity: usize) -> Self { - let layout = match Layout::from_size_align(capacity, SIMDJSON_PADDING) { - Ok(layout) => layout, - Err(_) => Self::capacity_overflow(), + let Ok(layout) = Layout::from_size_align(capacity, SIMDJSON_PADDING) else { + Self::capacity_overflow() }; if mem::size_of::() < 8 && capacity > isize::MAX as usize { Self::capacity_overflow() } - let inner = match unsafe { NonNull::new(alloc(layout)) } { - Some(ptr) => ptr, - None => handle_alloc_error(layout), + let Some(inner) = (unsafe { NonNull::new(alloc(layout)) }) else { + handle_alloc_error(layout) }; Self { layout, diff --git a/src/serde/value/borrowed/de.rs b/src/serde/value/borrowed/de.rs index 68d7108a..2a9f00ad 100644 --- a/src/serde/value/borrowed/de.rs +++ b/src/serde/value/borrowed/de.rs @@ -81,11 +81,8 @@ impl<'de> de::Deserializer<'de> for Value<'de> { let (variant, value) = match self { Value::Object(value) => { let mut iter = value.into_iter(); - let (variant, value) = match iter.next() { - Some(v) => v, - None => { - return Err(crate::Deserializer::error(ErrorType::Eof)); - } + let Some((variant, value)) = iter.next() else { + return Err(crate::Deserializer::error(ErrorType::Eof)); }; // enums are encoded in json as maps with a single key:value pair if iter.next().is_some() { @@ -687,11 +684,8 @@ impl<'de> de::Deserializer<'de> for &'de Value<'de> { let (variant, value) = match self { Value::Object(value) => { let mut iter = value.iter(); - let (variant, value) = match iter.next() { - Some(v) => v, - None => { - return Err(crate::Deserializer::error(ErrorType::Eof)); - } + let Some((variant, value)) = iter.next() else { + return Err(crate::Deserializer::error(ErrorType::Eof)); }; // enums are encoded in json as maps with a single key:value pair if iter.next().is_some() { diff --git a/src/serde/value/owned/de.rs b/src/serde/value/owned/de.rs index 54214545..bb45dd44 100644 --- a/src/serde/value/owned/de.rs +++ b/src/serde/value/owned/de.rs @@ -69,11 +69,8 @@ impl<'de> de::Deserializer<'de> for Value { let (variant, value) = match self { Value::Object(value) => { let mut iter = value.into_iter(); - let (variant, value) = match iter.next() { - Some(v) => v, - None => { - return Err(crate::Deserializer::error(ErrorType::Eof)); - } + let Some((variant, value)) = iter.next() else { + return Err(crate::Deserializer::error(ErrorType::Eof)); }; // enums are encoded in json as maps with a single key:value pair if iter.next().is_some() { @@ -675,11 +672,8 @@ impl<'de> de::Deserializer<'de> for &'de Value { let (variant, value) = match self { Value::Object(value) => { let mut iter = value.iter(); - let (variant, value) = match iter.next() { - Some(v) => v, - None => { - return Err(crate::Deserializer::error(ErrorType::Eof)); - } + let Some((variant, value)) = iter.next() else { + return Err(crate::Deserializer::error(ErrorType::Eof)); }; // enums are encoded in json as maps with a single key:value pair if iter.next().is_some() { diff --git a/src/stringparse.rs b/src/stringparse.rs index 6c5fcaac..f35a9f5e 100644 --- a/src/stringparse.rs +++ b/src/stringparse.rs @@ -71,14 +71,10 @@ pub(crate) fn get_unicode_codepoint(mut src_ptr: &[u8]) -> Result<(u32, usize), if ((code_point | code_point_2) >> 16) != 0 { return Ok((0, src_offset)); } - let c1 = if let Some(c) = code_point.checked_sub(0xd800) { - c - } else { + let Some(c1) = code_point.checked_sub(0xd800) else { return Err(ErrorType::InvalidUtf8); }; - let c2 = if let Some(c) = code_point_2.checked_sub(0xdc00) { - c - } else { + let Some(c2) = code_point_2.checked_sub(0xdc00) else { return Err(ErrorType::InvalidUtf8); }; code_point = ((c1 << 10) | c2) + 0x10000; diff --git a/src/value/borrowed/cmp.rs b/src/value/borrowed/cmp.rs index c8c11a9f..d5749002 100644 --- a/src/value/borrowed/cmp.rs +++ b/src/value/borrowed/cmp.rs @@ -49,7 +49,7 @@ impl<'v> PartialEq for Value<'v> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &bool) -> bool { - self.as_bool().map(|t| t.eq(other)).unwrap_or_default() + self.as_bool().is_some_and(|t| t.eq(other)) } } @@ -57,7 +57,7 @@ impl<'v> PartialEq for Value<'v> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &str) -> bool { - self.as_str().map(|t| t.eq(other)).unwrap_or_default() + self.as_str().is_some_and(|t| t.eq(other)) } } @@ -73,7 +73,7 @@ impl<'v> PartialEq for Value<'v> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &String) -> bool { - self.as_str().map(|t| t.eq(other)).unwrap_or_default() + self.as_str().is_some_and(|t| t.eq(other)) } } @@ -81,7 +81,7 @@ impl<'v> PartialEq for Value<'v> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &i8) -> bool { - self.as_i8().map(|t| t.eq(other)).unwrap_or_default() + self.as_i8().is_some_and(|t| t.eq(other)) } } @@ -89,7 +89,7 @@ impl<'v> PartialEq for Value<'v> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &i16) -> bool { - self.as_i16().map(|t| t.eq(other)).unwrap_or_default() + self.as_i16().is_some_and(|t| t.eq(other)) } } @@ -97,7 +97,7 @@ impl<'v> PartialEq for Value<'v> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &i32) -> bool { - self.as_i32().map(|t| t.eq(other)).unwrap_or_default() + self.as_i32().is_some_and(|t| t.eq(other)) } } @@ -105,7 +105,7 @@ impl<'v> PartialEq for Value<'v> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &i64) -> bool { - self.as_i64().map(|t| t.eq(other)).unwrap_or_default() + self.as_i64().is_some_and(|t| t.eq(other)) } } @@ -113,7 +113,7 @@ impl<'v> PartialEq for Value<'v> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &i128) -> bool { - self.as_i128().map(|t| t.eq(other)).unwrap_or_default() + self.as_i128().is_some_and(|t| t.eq(other)) } } @@ -121,7 +121,7 @@ impl<'v> PartialEq for Value<'v> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &u8) -> bool { - self.as_u8().map(|t| t.eq(other)).unwrap_or_default() + self.as_u8().is_some_and(|t| t.eq(other)) } } @@ -129,7 +129,7 @@ impl<'v> PartialEq for Value<'v> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &u16) -> bool { - self.as_u16().map(|t| t.eq(other)).unwrap_or_default() + self.as_u16().is_some_and(|t| t.eq(other)) } } @@ -137,7 +137,7 @@ impl<'v> PartialEq for Value<'v> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &u32) -> bool { - self.as_u32().map(|t| t.eq(other)).unwrap_or_default() + self.as_u32().is_some_and(|t| t.eq(other)) } } @@ -145,7 +145,7 @@ impl<'v> PartialEq for Value<'v> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &u64) -> bool { - self.as_u64().map(|t| t.eq(other)).unwrap_or_default() + self.as_u64().is_some_and(|t| t.eq(other)) } } @@ -153,7 +153,7 @@ impl<'v> PartialEq for Value<'v> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &usize) -> bool { - self.as_usize().map(|t| t.eq(other)).unwrap_or_default() + self.as_usize().is_some_and(|t| t.eq(other)) } } @@ -161,7 +161,7 @@ impl<'v> PartialEq for Value<'v> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &u128) -> bool { - self.as_u128().map(|t| t.eq(other)).unwrap_or_default() + self.as_u128().is_some_and(|t| t.eq(other)) } } @@ -169,7 +169,7 @@ impl<'v> PartialEq for Value<'v> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &f32) -> bool { - self.as_f32().map(|t| t.eq(other)).unwrap_or_default() + self.as_f32().is_some_and(|t| t.eq(other)) } } @@ -177,7 +177,7 @@ impl<'v> PartialEq for Value<'v> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &f64) -> bool { - self.as_f64().map(|t| t.eq(other)).unwrap_or_default() + self.as_f64().is_some_and(|t| t.eq(other)) } } @@ -188,7 +188,7 @@ where #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &&[T]) -> bool { - self.as_array().map(|t| t.eq(other)).unwrap_or_default() + self.as_array().is_some_and(|t| t.eq(other)) } } diff --git a/src/value/borrowed/serialize.rs b/src/value/borrowed/serialize.rs index 90589798..96bd5be5 100644 --- a/src/value/borrowed/serialize.rs +++ b/src/value/borrowed/serialize.rs @@ -60,9 +60,7 @@ trait Generator: BaseGenerator { stry!(self.write(b"{")); // We know this exists since it's not empty - let (key, value) = if let Some(v) = iter.next() { - v - } else { + let Some((key, value)) = iter.next() else { // We check against size unreachable!(); }; @@ -107,9 +105,7 @@ trait Generator: BaseGenerator { let mut iter = <[Value]>::iter(array); // We know we have one item - let item = if let Some(v) = iter.next() { - v - } else { + let Some(item) = iter.next() else { // We check against size unreachable!(); }; @@ -146,9 +142,7 @@ trait FastGenerator: BaseGenerator { stry!(self.write(b"{\"")); // We know this exists since it's not empty - let (key, value) = if let Some(v) = iter.next() { - v - } else { + let Some((key, value)) = iter.next() else { // We check against size unreachable!(); }; @@ -187,9 +181,7 @@ trait FastGenerator: BaseGenerator { } else { let mut iter = <[Value]>::iter(array); // We know we have one item - let item = if let Some(v) = iter.next() { - v - } else { + let Some(item) = iter.next() else { // We check against size unreachable!(); }; diff --git a/src/value/lazy/cmp.rs b/src/value/lazy/cmp.rs index 4e54998a..f99d3d1c 100644 --- a/src/value/lazy/cmp.rs +++ b/src/value/lazy/cmp.rs @@ -15,7 +15,7 @@ impl<'borrow, 'tape, 'input> PartialEq for Value<'borrow, 'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &bool) -> bool { - self.as_bool().map(|t| t.eq(other)).unwrap_or_default() + self.as_bool().is_some_and(|t| t.eq(other)) } } @@ -23,7 +23,7 @@ impl<'borrow, 'tape, 'input> PartialEq for Value<'borrow, 'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &str) -> bool { - self.as_str().map(|t| t.eq(other)).unwrap_or_default() + self.as_str().is_some_and(|t| t.eq(other)) } } @@ -39,7 +39,7 @@ impl<'borrow, 'tape, 'input> PartialEq for Value<'borrow, 'tape, 'input> #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &String) -> bool { - self.as_str().map(|t| t.eq(other)).unwrap_or_default() + self.as_str().is_some_and(|t| t.eq(other)) } } @@ -47,7 +47,7 @@ impl<'borrow, 'tape, 'input> PartialEq for Value<'borrow, 'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &i8) -> bool { - self.as_i8().map(|t| t.eq(other)).unwrap_or_default() + self.as_i8().is_some_and(|t| t.eq(other)) } } @@ -55,7 +55,7 @@ impl<'borrow, 'tape, 'input> PartialEq for Value<'borrow, 'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &i16) -> bool { - self.as_i16().map(|t| t.eq(other)).unwrap_or_default() + self.as_i16().is_some_and(|t| t.eq(other)) } } @@ -63,7 +63,7 @@ impl<'borrow, 'tape, 'input> PartialEq for Value<'borrow, 'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &i32) -> bool { - self.as_i32().map(|t| t.eq(other)).unwrap_or_default() + self.as_i32().is_some_and(|t| t.eq(other)) } } @@ -71,7 +71,7 @@ impl<'borrow, 'tape, 'input> PartialEq for Value<'borrow, 'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &i64) -> bool { - self.as_i64().map(|t| t.eq(other)).unwrap_or_default() + self.as_i64().is_some_and(|t| t.eq(other)) } } @@ -79,7 +79,7 @@ impl<'borrow, 'tape, 'input> PartialEq for Value<'borrow, 'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &i128) -> bool { - self.as_i128().map(|t| t.eq(other)).unwrap_or_default() + self.as_i128().is_some_and(|t| t.eq(other)) } } @@ -87,7 +87,7 @@ impl<'borrow, 'tape, 'input> PartialEq for Value<'borrow, 'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &u8) -> bool { - self.as_u8().map(|t| t.eq(other)).unwrap_or_default() + self.as_u8().is_some_and(|t| t.eq(other)) } } @@ -95,7 +95,7 @@ impl<'borrow, 'tape, 'input> PartialEq for Value<'borrow, 'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &u16) -> bool { - self.as_u16().map(|t| t.eq(other)).unwrap_or_default() + self.as_u16().is_some_and(|t| t.eq(other)) } } @@ -103,7 +103,7 @@ impl<'borrow, 'tape, 'input> PartialEq for Value<'borrow, 'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &u32) -> bool { - self.as_u32().map(|t| t.eq(other)).unwrap_or_default() + self.as_u32().is_some_and(|t| t.eq(other)) } } @@ -111,7 +111,7 @@ impl<'borrow, 'tape, 'input> PartialEq for Value<'borrow, 'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &u64) -> bool { - self.as_u64().map(|t| t.eq(other)).unwrap_or_default() + self.as_u64().is_some_and(|t| t.eq(other)) } } @@ -119,7 +119,7 @@ impl<'borrow, 'tape, 'input> PartialEq for Value<'borrow, 'tape, 'input> #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &usize) -> bool { - self.as_usize().map(|t| t.eq(other)).unwrap_or_default() + self.as_usize().is_some_and(|t| t.eq(other)) } } @@ -127,7 +127,7 @@ impl<'borrow, 'tape, 'input> PartialEq for Value<'borrow, 'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &u128) -> bool { - self.as_u128().map(|t| t.eq(other)).unwrap_or_default() + self.as_u128().is_some_and(|t| t.eq(other)) } } @@ -135,7 +135,7 @@ impl<'borrow, 'tape, 'input> PartialEq for Value<'borrow, 'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &f32) -> bool { - self.as_f32().map(|t| t.eq(other)).unwrap_or_default() + self.as_f32().is_some_and(|t| t.eq(other)) } } @@ -143,7 +143,7 @@ impl<'borrow, 'tape, 'input> PartialEq for Value<'borrow, 'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &f64) -> bool { - self.as_f64().map(|t| t.eq(other)).unwrap_or_default() + self.as_f64().is_some_and(|t| t.eq(other)) } } diff --git a/src/value/owned/cmp.rs b/src/value/owned/cmp.rs index 63dfa897..294c3f50 100644 --- a/src/value/owned/cmp.rs +++ b/src/value/owned/cmp.rs @@ -60,7 +60,7 @@ impl PartialEq for Value { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &bool) -> bool { - self.as_bool().map(|t| t.eq(other)).unwrap_or_default() + self.as_bool().is_some_and(|t| t.eq(other)) } } @@ -68,7 +68,7 @@ impl PartialEq for Value { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &str) -> bool { - self.as_str().map(|t| t.eq(other)).unwrap_or_default() + self.as_str().is_some_and(|t| t.eq(other)) } } @@ -84,7 +84,7 @@ impl PartialEq for Value { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &String) -> bool { - self.as_str().map(|t| t.eq(other)).unwrap_or_default() + self.as_str().is_some_and(|t| t.eq(other)) } } @@ -92,7 +92,7 @@ impl PartialEq for Value { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &i8) -> bool { - self.as_i8().map(|t| t.eq(other)).unwrap_or_default() + self.as_i8().is_some_and(|t| t.eq(other)) } } @@ -100,7 +100,7 @@ impl PartialEq for Value { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &i16) -> bool { - self.as_i16().map(|t| t.eq(other)).unwrap_or_default() + self.as_i16().is_some_and(|t| t.eq(other)) } } @@ -108,7 +108,7 @@ impl PartialEq for Value { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &i32) -> bool { - self.as_i32().map(|t| t.eq(other)).unwrap_or_default() + self.as_i32().is_some_and(|t| t.eq(other)) } } @@ -116,7 +116,7 @@ impl PartialEq for Value { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &i64) -> bool { - self.as_i64().map(|t| t.eq(other)).unwrap_or_default() + self.as_i64().is_some_and(|t| t.eq(other)) } } @@ -124,7 +124,7 @@ impl PartialEq for Value { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &i128) -> bool { - self.as_i128().map(|t| t.eq(other)).unwrap_or_default() + self.as_i128().is_some_and(|t| t.eq(other)) } } @@ -132,7 +132,7 @@ impl PartialEq for Value { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &u8) -> bool { - self.as_u8().map(|t| t.eq(other)).unwrap_or_default() + self.as_u8().is_some_and(|t| t.eq(other)) } } @@ -140,7 +140,7 @@ impl PartialEq for Value { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &u16) -> bool { - self.as_u16().map(|t| t.eq(other)).unwrap_or_default() + self.as_u16().is_some_and(|t| t.eq(other)) } } @@ -148,7 +148,7 @@ impl PartialEq for Value { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &u32) -> bool { - self.as_u32().map(|t| t.eq(other)).unwrap_or_default() + self.as_u32().is_some_and(|t| t.eq(other)) } } @@ -156,7 +156,7 @@ impl PartialEq for Value { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &u64) -> bool { - self.as_u64().map(|t| t.eq(other)).unwrap_or_default() + self.as_u64().is_some_and(|t| t.eq(other)) } } @@ -164,7 +164,7 @@ impl PartialEq for Value { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &usize) -> bool { - self.as_usize().map(|t| t.eq(other)).unwrap_or_default() + self.as_usize().is_some_and(|t| t.eq(other)) } } @@ -172,7 +172,7 @@ impl PartialEq for Value { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &u128) -> bool { - self.as_u128().map(|t| t.eq(other)).unwrap_or_default() + self.as_u128().is_some_and(|t| t.eq(other)) } } @@ -180,7 +180,7 @@ impl PartialEq for Value { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &f32) -> bool { - self.as_f32().map(|t| t.eq(other)).unwrap_or_default() + self.as_f32().is_some_and(|t| t.eq(other)) } } @@ -188,7 +188,7 @@ impl PartialEq for Value { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &f64) -> bool { - self.as_f64().map(|t| t.eq(other)).unwrap_or_default() + self.as_f64().is_some_and(|t| t.eq(other)) } } @@ -199,7 +199,7 @@ where #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &&[T]) -> bool { - self.as_array().map(|t| t.eq(other)).unwrap_or_default() + self.as_array().is_some_and(|t| t.eq(other)) } } impl PartialEq> for Value diff --git a/src/value/owned/serialize.rs b/src/value/owned/serialize.rs index 408bbfea..b2b9b88b 100644 --- a/src/value/owned/serialize.rs +++ b/src/value/owned/serialize.rs @@ -60,9 +60,7 @@ trait Generator: BaseGenerator { stry!(self.write(b"{")); // We know this exists since it's not empty - let (key, value) = if let Some(v) = iter.next() { - v - } else { + let Some((key, value)) = iter.next() else { // We check against size unreachable!(); }; @@ -107,9 +105,7 @@ trait Generator: BaseGenerator { let mut iter = <[Value]>::iter(array); // We know we have one item - let item = if let Some(v) = iter.next() { - v - } else { + let Some(item) = iter.next() else { // We check against size unreachable!(); }; @@ -148,9 +144,7 @@ trait FastGenerator: BaseGenerator { stry!(self.write(b"{\"")); // We know this exists since it's not empty - let (key, value) = if let Some(v) = iter.next() { - v - } else { + let Some((key, value)) = iter.next() else { // We check against size unreachable!(); }; @@ -189,9 +183,7 @@ trait FastGenerator: BaseGenerator { } else { let mut iter = <[Value]>::iter(array); // We know we have one item - let item = if let Some(v) = iter.next() { - v - } else { + let Some(item) = iter.next() else { // We check against size unreachable!(); }; diff --git a/src/value/tape/cmp.rs b/src/value/tape/cmp.rs index d79b8e00..d803316f 100644 --- a/src/value/tape/cmp.rs +++ b/src/value/tape/cmp.rs @@ -36,7 +36,7 @@ impl<'tape, 'input> PartialEq for Value<'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &bool) -> bool { - self.as_bool().map(|t| t.eq(other)).unwrap_or_default() + self.as_bool().is_some_and(|t| t.eq(other)) } } @@ -44,7 +44,7 @@ impl<'tape, 'input> PartialEq for Value<'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &str) -> bool { - self.as_str().map(|t| t.eq(other)).unwrap_or_default() + self.as_str().is_some_and(|t| t.eq(other)) } } @@ -60,7 +60,7 @@ impl<'tape, 'input> PartialEq for Value<'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &String) -> bool { - self.as_str().map(|t| t.eq(other)).unwrap_or_default() + self.as_str().is_some_and(|t| t.eq(other)) } } @@ -68,7 +68,7 @@ impl<'tape, 'input> PartialEq for Value<'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &i8) -> bool { - self.as_i8().map(|t| t.eq(other)).unwrap_or_default() + self.as_i8().is_some_and(|t| t.eq(other)) } } @@ -76,7 +76,7 @@ impl<'tape, 'input> PartialEq for Value<'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &i16) -> bool { - self.as_i16().map(|t| t.eq(other)).unwrap_or_default() + self.as_i16().is_some_and(|t| t.eq(other)) } } @@ -84,7 +84,7 @@ impl<'tape, 'input> PartialEq for Value<'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &i32) -> bool { - self.as_i32().map(|t| t.eq(other)).unwrap_or_default() + self.as_i32().is_some_and(|t| t.eq(other)) } } @@ -92,7 +92,7 @@ impl<'tape, 'input> PartialEq for Value<'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &i64) -> bool { - self.as_i64().map(|t| t.eq(other)).unwrap_or_default() + self.as_i64().is_some_and(|t| t.eq(other)) } } @@ -100,7 +100,7 @@ impl<'tape, 'input> PartialEq for Value<'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &i128) -> bool { - self.as_i128().map(|t| t.eq(other)).unwrap_or_default() + self.as_i128().is_some_and(|t| t.eq(other)) } } @@ -108,7 +108,7 @@ impl<'tape, 'input> PartialEq for Value<'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &u8) -> bool { - self.as_u8().map(|t| t.eq(other)).unwrap_or_default() + self.as_u8().is_some_and(|t| t.eq(other)) } } @@ -116,7 +116,7 @@ impl<'tape, 'input> PartialEq for Value<'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &u16) -> bool { - self.as_u16().map(|t| t.eq(other)).unwrap_or_default() + self.as_u16().is_some_and(|t| t.eq(other)) } } @@ -124,7 +124,7 @@ impl<'tape, 'input> PartialEq for Value<'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &u32) -> bool { - self.as_u32().map(|t| t.eq(other)).unwrap_or_default() + self.as_u32().is_some_and(|t| t.eq(other)) } } @@ -132,7 +132,7 @@ impl<'tape, 'input> PartialEq for Value<'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &u64) -> bool { - self.as_u64().map(|t| t.eq(other)).unwrap_or_default() + self.as_u64().is_some_and(|t| t.eq(other)) } } @@ -140,7 +140,7 @@ impl<'tape, 'input> PartialEq for Value<'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &usize) -> bool { - self.as_usize().map(|t| t.eq(other)).unwrap_or_default() + self.as_usize().is_some_and(|t| t.eq(other)) } } @@ -148,7 +148,7 @@ impl<'tape, 'input> PartialEq for Value<'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &u128) -> bool { - self.as_u128().map(|t| t.eq(other)).unwrap_or_default() + self.as_u128().is_some_and(|t| t.eq(other)) } } @@ -156,7 +156,7 @@ impl<'tape, 'input> PartialEq for Value<'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &f32) -> bool { - self.as_f32().map(|t| t.eq(other)).unwrap_or_default() + self.as_f32().is_some_and(|t| t.eq(other)) } } @@ -164,7 +164,7 @@ impl<'tape, 'input> PartialEq for Value<'tape, 'input> { #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn eq(&self, other: &f64) -> bool { - self.as_f64().map(|t| t.eq(other)).unwrap_or_default() + self.as_f64().is_some_and(|t| t.eq(other)) } } diff --git a/src/value/tape/trait_impls.rs b/src/value/tape/trait_impls.rs index e3c652b1..92066d0e 100644 --- a/src/value/tape/trait_impls.rs +++ b/src/value/tape/trait_impls.rs @@ -702,9 +702,7 @@ trait Generator: BaseGenerator { stry!(self.write(b"{")); // We know this exists since it's not empty - let (key, value) = if let Some(v) = iter.next() { - v - } else { + let Some((key, value)) = iter.next() else { // We check against size unreachable!(); }; @@ -751,9 +749,7 @@ trait Generator: BaseGenerator { let mut iter = array.iter(); // We know we have one item - let item = if let Some(v) = iter.next() { - v - } else { + let Some(item) = iter.next() else { // We check against size unreachable!(); }; @@ -790,9 +786,7 @@ trait FastGenerator: BaseGenerator { stry!(self.write(b"{\"")); // We know this exists since it's not empty - let (key, value) = if let Some(v) = iter.next() { - v - } else { + let Some((key, value)) = iter.next() else { // We check against size unreachable!(); }; @@ -832,9 +826,7 @@ trait FastGenerator: BaseGenerator { let array = Array(&json.0[..=count]); let mut iter = array.iter(); // We know we have one item - let item = if let Some(v) = iter.next() { - v - } else { + let Some(item) = iter.next() else { // We check against size unreachable!(); };