diff --git a/common/std-shims/src/lib.rs b/common/std-shims/src/lib.rs index bccda3a0..2c2e1090 100644 --- a/common/std-shims/src/lib.rs +++ b/common/std-shims/src/lib.rs @@ -11,3 +11,64 @@ pub mod io; pub use alloc::vec; pub use alloc::str; pub use alloc::string; + +pub mod prelude { + #[rustversion::before(1.73)] + #[doc(hidden)] + pub trait StdShimsDivCeil { + fn div_ceil(self, rhs: Self) -> Self; + } + #[rustversion::before(1.73)] + mod impl_divceil { + use super::StdShimsDivCeil; + impl StdShimsDivCeil for u8 { + fn div_ceil(self, rhs: Self) -> Self { + (self + (rhs - 1)) / rhs + } + } + impl StdShimsDivCeil for u16 { + fn div_ceil(self, rhs: Self) -> Self { + (self + (rhs - 1)) / rhs + } + } + impl StdShimsDivCeil for u32 { + fn div_ceil(self, rhs: Self) -> Self { + (self + (rhs - 1)) / rhs + } + } + impl StdShimsDivCeil for u64 { + fn div_ceil(self, rhs: Self) -> Self { + (self + (rhs - 1)) / rhs + } + } + impl StdShimsDivCeil for u128 { + fn div_ceil(self, rhs: Self) -> Self { + (self + (rhs - 1)) / rhs + } + } + impl StdShimsDivCeil for usize { + fn div_ceil(self, rhs: Self) -> Self { + (self + (rhs - 1)) / rhs + } + } + } + + #[cfg(feature = "std")] + #[rustversion::before(1.74)] + #[doc(hidden)] + pub trait StdShimsIoErrorOther { + fn other(error: E) -> Self + where + E: Into>; + } + #[cfg(feature = "std")] + #[rustversion::before(1.74)] + impl StdShimsIoErrorOther for std::io::Error { + fn other(error: E) -> Self + where + E: Into>, + { + std::io::Error::new(std::io::ErrorKind::Other, error) + } + } +}