From 432daae1d1c5646a83c5a86d7c16a18e63aa474b Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Tue, 19 Aug 2025 18:04:29 -0400 Subject: [PATCH] Polyfill extension traits for div_ceil and io::Error::other --- common/std-shims/src/lib.rs | 61 +++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) 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) + } + } +}