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  pub use alloc::{
17    format, vec,
18    boxed::Box,
19    borrow::ToOwned,
20    vec::Vec,
21    string::{String, ToString},
22  };
23
24  #[rustversion::before(1.73)]
25  #[doc(hidden)]
26  pub trait StdShimsDivCeil {
27    fn div_ceil(self, rhs: Self) -> Self;
28  }
29  #[rustversion::before(1.73)]
30  mod impl_divceil {
31    use super::StdShimsDivCeil;
32    impl StdShimsDivCeil for u8 {
33      fn div_ceil(self, rhs: Self) -> Self {
34        (self + (rhs - 1)) / rhs
35      }
36    }
37    impl StdShimsDivCeil for u16 {
38      fn div_ceil(self, rhs: Self) -> Self {
39        (self + (rhs - 1)) / rhs
40      }
41    }
42    impl StdShimsDivCeil for u32 {
43      fn div_ceil(self, rhs: Self) -> Self {
44        (self + (rhs - 1)) / rhs
45      }
46    }
47    impl StdShimsDivCeil for u64 {
48      fn div_ceil(self, rhs: Self) -> Self {
49        (self + (rhs - 1)) / rhs
50      }
51    }
52    impl StdShimsDivCeil for u128 {
53      fn div_ceil(self, rhs: Self) -> Self {
54        (self + (rhs - 1)) / rhs
55      }
56    }
57    impl StdShimsDivCeil for usize {
58      fn div_ceil(self, rhs: Self) -> Self {
59        (self + (rhs - 1)) / rhs
60      }
61    }
62  }
63
64  #[cfg(feature = "std")]
65  #[rustversion::before(1.74)]
66  #[doc(hidden)]
67  pub trait StdShimsIoErrorOther {
68    fn other<E>(error: E) -> Self
69    where
70      E: Into<Box<dyn std::error::Error + Send + Sync>>;
71  }
72  #[cfg(feature = "std")]
73  #[rustversion::before(1.74)]
74  impl StdShimsIoErrorOther for std::io::Error {
75    fn other<E>(error: E) -> Self
76    where
77      E: Into<Box<dyn std::error::Error + Send + Sync>>,
78    {
79      std::io::Error::new(std::io::ErrorKind::Other, error)
80    }
81  }
82}