std_shims/
lib.rs

1#![cfg_attr(docsrs, feature(doc_auto_cfg))]
2#![doc = include_str!("../README.md")]
3#![cfg_attr(not(feature = "std"), no_std)]
4
5pub extern crate alloc;
6
7pub mod sync;
8pub mod collections;
9pub mod io;
10
11pub use alloc::vec;
12pub use alloc::str;
13pub use alloc::string;
14
15pub mod prelude {
16  #[rustversion::before(1.73)]
17  #[doc(hidden)]
18  pub trait StdShimsDivCeil {
19    fn div_ceil(self, rhs: Self) -> Self;
20  }
21  #[rustversion::before(1.73)]
22  mod impl_divceil {
23    use super::StdShimsDivCeil;
24    impl StdShimsDivCeil for u8 {
25      fn div_ceil(self, rhs: Self) -> Self {
26        (self + (rhs - 1)) / rhs
27      }
28    }
29    impl StdShimsDivCeil for u16 {
30      fn div_ceil(self, rhs: Self) -> Self {
31        (self + (rhs - 1)) / rhs
32      }
33    }
34    impl StdShimsDivCeil for u32 {
35      fn div_ceil(self, rhs: Self) -> Self {
36        (self + (rhs - 1)) / rhs
37      }
38    }
39    impl StdShimsDivCeil for u64 {
40      fn div_ceil(self, rhs: Self) -> Self {
41        (self + (rhs - 1)) / rhs
42      }
43    }
44    impl StdShimsDivCeil for u128 {
45      fn div_ceil(self, rhs: Self) -> Self {
46        (self + (rhs - 1)) / rhs
47      }
48    }
49    impl StdShimsDivCeil for usize {
50      fn div_ceil(self, rhs: Self) -> Self {
51        (self + (rhs - 1)) / rhs
52      }
53    }
54  }
55
56  #[cfg(feature = "std")]
57  #[rustversion::before(1.74)]
58  #[doc(hidden)]
59  pub trait StdShimsIoErrorOther {
60    fn other<E>(error: E) -> Self
61    where
62      E: Into<Box<dyn std::error::Error + Send + Sync>>;
63  }
64  #[cfg(feature = "std")]
65  #[rustversion::before(1.74)]
66  impl StdShimsIoErrorOther for std::io::Error {
67    fn other<E>(error: E) -> Self
68    where
69      E: Into<Box<dyn std::error::Error + Send + Sync>>,
70    {
71      std::io::Error::new(std::io::ErrorKind::Other, error)
72    }
73  }
74}