diff --git a/src/error.rs b/src/error.rs index 5b7b642..9cb2a90 100644 --- a/src/error.rs +++ b/src/error.rs @@ -52,6 +52,4 @@ impl Display for Error { f.write_str("bitcode error") } } -#[cfg(feature = "std")] -// TODO expose to no_std when error_in_core stabilized (https://github.com/rust-lang/rust/issues/103765) -impl std::error::Error for Error {} +impl core::error::Error for Error {} diff --git a/src/lib.rs b/src/lib.rs index d82e0ee..09640a8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,7 +26,6 @@ mod fast; mod histogram; mod int; mod length; -mod nightly; mod pack; mod pack_ints; mod pack_shared; diff --git a/src/nightly.rs b/src/nightly.rs deleted file mode 100644 index 2215297..0000000 --- a/src/nightly.rs +++ /dev/null @@ -1,18 +0,0 @@ -/// `#![feature(int_roundings)]` was stabilized in 1.73, but we want to avoid MSRV that high. -macro_rules! impl_div_ceil { - ($name:ident, $t:ty) => { - #[inline(always)] - #[allow(unused_comparisons)] // < 0 checks not required for unsigned - pub const fn $name(lhs: $t, rhs: $t) -> $t { - let d = lhs / rhs; - let r = lhs % rhs; - if (r > 0 && rhs > 0) || (r < 0 && rhs < 0) { - d + 1 - } else { - d - } - } - }; -} -impl_div_ceil!(div_ceil_u8, u8); -impl_div_ceil!(div_ceil_usize, usize); diff --git a/src/pack.rs b/src/pack.rs index 2a47746..bf79918 100644 --- a/src/pack.rs +++ b/src/pack.rs @@ -44,7 +44,7 @@ impl PackingTrait for Packing { impl Packing { fn read(input: &mut &[u8]) -> Result<(Self, bool)> { let v = consume_byte(input)?; - let p_u8 = crate::nightly::div_ceil_u8(v, 2); + let p_u8 = v.div_ceil(2); let offset_by_min = v & 1 != 0; let p = match p_u8 { 0 => Self::_256, @@ -280,7 +280,7 @@ pub fn unpack_bytes_less_than<'a, const N: usize, const HISTOGRAM: usize>( check_less_than_u8::(out) } else { let floor = length / divisor; - let ceil = crate::nightly::div_ceil_usize(length, divisor); + let ceil = length.div_ceil(divisor); let whole = &original_input[..floor]; // Can only `partial_with_garbage % FACTOR` partial_length times as the rest are undefined garbage. @@ -335,6 +335,7 @@ pub fn unpack_bytes_less_than<'a, const N: usize, const HISTOGRAM: usize>( }) }; if let Ok(h) = histogram { + debug_assert!(check_less_than_u8::(out).is_ok()); debug_assert_eq!( h, check_histogram(crate::histogram::histogram(out)).unwrap() @@ -439,7 +440,7 @@ fn unpack_arithmetic( // TODO STRICT: check that packed.all(|&b| b < FACTOR.powi(divisor)). let floor = unpacked_len / divisor; - let ceil = crate::nightly::div_ceil_usize(unpacked_len, divisor); + let ceil = unpacked_len.div_ceil(divisor); let packed = consume_bytes(input, ceil)?; debug_assert!(out.is_empty()); @@ -666,15 +667,18 @@ mod tests { bench_n!(bench_unpack_arithmetic, 2, 3, 4, 6, 16); fn test_pack_bytes_less_than_n() { - for n in [1, 11, 97, 991, 10007].into_iter().flat_map(|n_prime| { - let divisor = if FACTOR == 256 { - 1 - } else { - super::factor_to_divisor::() - }; - let n_factor = crate::nightly::div_ceil_usize(n_prime, divisor) * divisor; - [n_factor, n_prime] - }) { + for n in [1usize, 11, 97, 991, 10007] + .into_iter() + .flat_map(|n_prime| { + let divisor = if FACTOR == 256 { + 1 + } else { + super::factor_to_divisor::() + }; + let n_factor = n_prime.div_ceil(divisor) * divisor; + [n_factor, n_prime] + }) + { let bytes: Vec<_> = crate::random_data(n) .into_iter() .map(|v: usize| (v % N as usize) as u8) diff --git a/src/pack_ints.rs b/src/pack_ints.rs index d9c528f..d73c503 100644 --- a/src/pack_ints.rs +++ b/src/pack_ints.rs @@ -43,7 +43,7 @@ impl PackingTrait for Packing { impl Packing { fn read(input: &mut &[u8]) -> Result<(Self, bool)> { let v = consume_byte(input)?; - let p_u8 = crate::nightly::div_ceil_u8(v, 2) + Self::new(T::MAX) as u8; + let p_u8 = v.div_ceil(2) + Self::new(T::MAX) as u8; let offset_by_min = v & 1 != 0; let p = match p_u8 { 0 => Self::_128, diff --git a/src/serde/mod.rs b/src/serde/mod.rs index 0d49bce..a8356ee 100644 --- a/src/serde/mod.rs +++ b/src/serde/mod.rs @@ -46,9 +46,6 @@ fn get_mut_or_resize(vec: &mut Vec, index: usize) -> &mut T { unsafe { vec.get_unchecked_mut(index) } } -#[cfg(not(feature = "std"))] -impl serde::ser::StdError for Error {} - impl serde::ser::Error for Error { fn custom(t: T) -> Self where