standback/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2#![deny(rust_2018_idioms, unused_qualifications)]
3#![warn(unreachable_pub)]
4#![allow(non_camel_case_types, unstable_name_collisions, clippy::all)]
5
6/*!
7Standback backports a number of methods, structs, and macros that have been stabilized in the Rust
8standard library since 1.36.0. This allows crate authors to depend on Standback rather than forcing
9downstream users to upgrade their compiler (or not use the new feature at all).
10
11Due to a variety of restrictions in the Rust, it is not possible to implement everything that has
12been stabilized.
13
14# Usage
15
16For most cases, importing the shims should suffice.
17
18```rust,no_run
19use standback::shim::*;
20```
21
22If you are using anything that would normally have to be imported, just use the `standback` crate
23instead of `core`, `alloc`, or `std`.
24
25```rust,no_run
26use standback::mem::take;
27```
28
29It is _highly_ recommended to use `#![allow(unstable_name_collisions)]`, as that's the whole point
30of this crate. Just be extra-careful to not do it for anything that _can't_ be backported.
31
32# `#![no_std]` support
33
34By default, there standard library is used where necessary. If support for `#![no_std]` is required,
35use `default-features = false`.
36
37Items that require an allocator are gated under the `alloc` feature, which is enabled by default via
38the `std` feature.
39
40# Minimum supported Rust version
41
42By default, this crate has a minimum supported Rust version of 1.36. If you do not require a MSRV
43this low, you can raise it by using `default-features = false` (be sure to re-enable `std` or
44`alloc` if you need it) and enabling a `msrv-1.XX` feature flag, substituting the appropriate
45version; the standback crate is not guaranteed to work (let alone produce a reasonable result) if no
46MSRV is declared when `default-features = false`. All versions up to the most recent stable release
47of a compiler are supported.
48
49Note that items stabilized prior to the declared MSRV _will not_ be re-exported.
50
51# Inherent items
52
53The following methods and constants are available via the shim. For brevity, `i*` is `i8`, `i16`,
54`i32`, `i64`, `i128`, and `isize`; `u*` is `u8`, `u16`, `u32`, `u64`, `u128`, and `usize`.
55
56## 1.60
57
58```text
59u8::escape_ascii
60Vec::spare_capacity_mut
61MaybeUninit::assume_init_drop
62MaybeUninit::assume_init_read
63{i*, u*}::abs_diff
64```
65
66## 1.59
67
68```text
69Result::copied
70Result::cloned
71NonZeroU*::is_power_of_two
72```
73
74## 1.58
75
76```text
77Metadata::is_symlink
78Path::is_symlink
79{i*, u*}::saturating_div
80Option::unwrap_unchecked
81Result::unwrap_unchecked
82Result::unwrap_err_unchecked
83NonZeroU*::is_power_of_two
84File::options
85```
86
87## 1.57
88
89```text
90Iterator::map_while
91```
92
93## 1.56
94
95None :(
96
97## 1.55
98
99```text
100prelude::rust_2015
101prelude::rust_2018
102prelude::rust_2021
103Bounded::cloned
104MaybeUninit::assume_init_mut
105MaybeUninit::assume_init_ref
106MaybeUninit::write
107```
108
109## 1.54
110
111```text
112BTreeMap::into_keys
113BTreeMap::into_values
114HashMap::into_keys
115HashMap::into_values
116VecDeque::binary_search
117VecDeque::binary_search_by
118VecDeque::binary_search_by_key
119VecDeque::partition_point
120```
121
122## 1.53
123
124```text
125Ordering::is_eq
126Duration::ZERO
127Duration::is_zero
128Duration::saturating_add
129Duration::saturating_mul
130Duration::saturating_sub
131Option::insert
132Ordering::is_eq
133Ordering::is_ge
134Ordering::is_gt
135Ordering::is_le
136Ordering::is_lt
137Ordering::is_ne
138OsStr::make_ascii_lowercase
139OsStr::make_ascii_uppercase
140OsStr::to_ascii_lowercase
141OsStr::to_ascii_uppercase
142OsStr::is_ascii
143OsStr::eq_ignore_ascii_case
144Rc::decrement_strong_count
145Rc::increment_strong_count
146Vec::extend_from_within
147{f32, f64}::is_subnormal
148{i*, u*}::BITS
149```
150
151## 1.52
152
153```text
154char::MAX
155char::REPLACEMENT_CHARACTER
156char::UNICODE_VERSION
157char::decode_utf16
158char::from_digit
159char::from_u32_unchecked
160char::from_u32
161slice::partition_point
162str::rsplit_once
163str::split_once
164```
165
166## 1.51
167
168```text
169Arc::decrement_strong_count
170Arc::increment_strong_count
171Peekable::next_if_eq
172Peekable::next_if
173Seek::stream_position
174slice::fill_with
175slice::split_inclusive_mut
176slice::split_inclusive
177slice::strip_prefix
178slice::strip_suffix
179str::split_inclusive
180i*::unsigned_abs
181Poll::map_ok
182Poll::map_err
183```
184
185## 1.50
186
187```text
188bool::then
189btree_map::Entry::or_insert_with_key
190hash_map::Entry::or_insert_with_key
191{f32, f64}::clamp
192Ord::clamp
193RefCell::take
194slice::fill
195UnsafeCell::get_mut
196```
197
198## 1.49
199
200```text
201slice::select_nth_unstable
202slice::select_nth_unstable_by
203slice::select_nth_unstable_by_key
204```
205
206## 1.48
207
208```text
209slice::as_ptr_range
210slice::as_mut_ptr_range
211```
212
213## 1.47
214
215```text
216Range::is_empty
217Result::as_deref
218Result::as_deref_mut
219Vec::leak
220f32::TAU
221f64::TAU
222```
223
224## 1.46
225
226```text
227{i*, u*}::leading_ones
228{i*, u*}::trailing_ones
229Option::zip
230```
231
232## 1.45
233
234```text
235i*::saturating_abs
236i*::saturating_neg
237str::strip_prefix
238str::strip_suffix
239```
240
241## 1.44
242
243```text
244PathBuf::with_capacity
245PathBuf::capacity
246PathBuf::clear
247PathBuf::reserve
248PathBuf::reserve_exact
249PathBuf::shrink_to_fit
250Layout::align_to
251Layout::pad_to_align
252Layout::array
253Layout::extend
254{f32, f64}::to_int_unchecked
255```
256
257## 1.43
258
259```text
260{f32, f64}::RADIX
261{f32, f64}::MANTISSA_DIGITS
262{f32, f64}::DIGITS
263{f32, f64}::EPSILON
264{f32, f64}::MIN
265{f32, f64}::MIN_POSITIVE
266{f32, f64}::MAX
267{f32, f64}::MIN_EXP
268{f32, f64}::MAX_EXP
269{f32, f64}::MIN_10_EXP
270{f32, f64}::MAX_10_EXP
271{f32, f64}::NAN
272{f32, f64}::INFINITY
273{f32, f64}::NEG_INFINITY
274{i*, u*}::MIN
275{i*, u*}::MAX
276```
277
278## 1.42
279
280```text
281CondVar::wait_while
282CondVar::wait_timeout_while
283ManuallyDrop::take
284```
285
286## 1.41
287
288```text
289Result::map_or
290Result::map_or_else
291```
292
293## 1.40
294
295```text
296Option::as_deref
297Option::as_deref_mut
298{f32, f64}::to_be_bytes
299{f32, f64}::to_le_bytes
300{f32, f64}::to_ne_bytes
301{f32, f64}::from_be_bytes
302{f32, f64}::from_le_bytes
303{f32, f64}::from_ne_bytes
304slice::repeat
305```
306
307## 1.39
308
309None :(
310
311## 1.38
312
313```text
314<*const T>::cast
315<*mut T>::cast
316Duration::as_secs_f32
317Duration::as_secs_f64
318Duration::div_f32
319Duration::div_f64
320Duration::from_secs_f32
321Duration::from_secs_f64
322Duration::mul_f32
323Duration::mul_f64
324{i*, u*}::rem_euclid
325{i*, u*}::checked_rem_euclid
326{i*, u*}::wrapping_rem_euclid
327{i*, u*}::overflowing_rem_euclid
328{i*, u*}::div_euclid
329{i*, u*}::checked_div_euclid
330{i*, u*}::wrapping_div_euclid
331{i*, u*}::overflowing_div_euclid
332{f32, f64}::rem_euclid
333{f32, f64}::div_euclid
334```
335
336## 1.37
337
338```text
339Cell::from_mut
340Cell<[T]>::as_slice_of_cells
341DoubleEndedIterator::nth_back
342Option::xor
343slice::copy_within
344```
345
346# Free items
347
348```text
349thread::available_parallelism // 1.59
350iter::zip // 1.59
351array::from_ref // 1.53
352array::from_mut // 1.53
353cmp::min_by // 1.53
354cmp::max_by // 1.53
355cmp::min_by_key // 1.53
356cmp::max_by_key // 1.53
357task::Wake // 1.51
358future::pending // 1.48
359iter::zip // 1.59
360thread::available_parallelism // 1.59
361future::ready // 1.48
362{f32, f64}::consts::TAU // 1.47
363char::UNICODE_VERSION // 1.45
364{f32, f64}::consts::LOG10_2 // 1.43
365{f32, f64}::consts::LOG2_10 // 1.43
366iter::once_with // 1.43
367mem::take // 1.40
368```
369
370# Prelude macros (located in `standback::shim`)
371
372```text
373matches! // 1.42
374todo! // 1.39
375```
376*/
377
378#[allow(unused_extern_crates)]
379#[cfg(feature = "alloc")]
380extern crate alloc;
381
382mod inherent;
383mod pattern;
384
385mod free {
386    #[cfg(shim = "1.40")] pub(crate) mod v1_40;
387    #[cfg(shim = "1.43")] pub(crate) mod v1_43;
388    #[cfg(shim = "1.47")] pub(crate) mod v1_47;
389    #[cfg(shim = "1.48")] pub(crate) mod v1_48;
390    #[cfg(shim = "1.51")] pub(crate) mod v1_51;
391    #[cfg(shim = "1.53")] pub(crate) mod v1_53;
392    #[cfg(shim = "1.59")] pub(crate) mod v1_59;
393}
394
395#[doc(hidden)]
396pub mod shim {
397    #[cfg(shim = "1.39")]
398    pub use core::unimplemented as todo;
399
400    pub use crate::inherent::*;
401    #[cfg(shim = "1.42")] pub use crate::matches;
402}
403#[doc(hidden)]
404pub mod prelude {
405    #[cfg(not(feature = "std"))]
406    pub use core::prelude::v1 as rust_2015;
407    #[cfg(feature = "std")]
408    pub use std::prelude::v1 as rust_2015;
409
410    pub use rust_2015 as rust_2018;
411
412    pub mod rust_2021 {
413        pub use core::convert::{TryFrom, TryInto};
414        pub use core::iter::FromIterator;
415
416        pub use crate::prelude::rust_2015::*;
417    }
418}
419#[doc(hidden)]
420pub mod mem {
421    #[cfg(reexport = "1.40")] pub use core::mem::take;
422
423    #[cfg(shim = "1.40")]
424    pub use crate::free::v1_40::mem::*;
425}
426#[doc(hidden)]
427pub mod iter {
428    #[cfg(reexport = "1.57")]
429    pub use core::iter::MapWhile;
430    #[cfg(reexport = "1.43")]
431    pub use core::iter::{once_with, OnceWith};
432    #[cfg(reexport = "1.59")]
433    pub use core::iter::{zip, Zip};
434
435    #[cfg(shim = "1.43")]
436    pub use crate::free::v1_43::iter::*;
437    #[cfg(shim = "1.59")]
438    pub use crate::free::v1_59::{zip, Zip};
439    #[cfg(shim = "1.57")]
440    pub use crate::inherent::MapWhile;
441}
442#[doc(hidden)]
443pub mod task {
444    #[cfg(all(reexport = "1.51", feature = "alloc"))]
445    pub use alloc::task::Wake;
446
447    #[cfg(all(shim = "1.51", feature = "alloc"))]
448    pub use crate::free::v1_51::task::*;
449}
450#[doc(hidden)]
451pub mod f32 {
452    pub mod consts {
453        #[cfg(reexport = "1.47")]
454        pub use core::f32::consts::TAU;
455        #[cfg(reexport = "1.43")]
456        pub use core::f32::consts::{LOG10_2, LOG2_10};
457
458        #[cfg(shim = "1.43")]
459        pub use crate::free::v1_43::f32::consts::*;
460        #[cfg(shim = "1.47")]
461        pub use crate::free::v1_47::f32::consts::*;
462    }
463}
464#[doc(hidden)]
465pub mod f64 {
466    pub mod consts {
467        #[cfg(reexport = "1.47")]
468        pub use core::f64::consts::TAU;
469        #[cfg(reexport = "1.43")]
470        pub use core::f64::consts::{LOG10_2, LOG2_10};
471
472        #[cfg(shim = "1.43")]
473        pub use crate::free::v1_43::f64::consts::*;
474        #[cfg(shim = "1.47")]
475        pub use crate::free::v1_47::f64::consts::*;
476    }
477}
478#[doc(hidden)]
479pub mod char {
480    #[cfg(shim = "1.38")]
481    pub const UNICODE_VERSION: (u8, u8, u8) = (11, 0, 0);
482    #[cfg(all(reexport = "1.38", shim = "1.44"))]
483    pub const UNICODE_VERSION: (u8, u8, u8) = (12, 1, 0);
484    #[cfg(all(reexport = "1.44", shim = "1.45"))]
485    pub const UNICODE_VERSION: (u8, u8, u8) = (13, 0, 0);
486    #[cfg(reexport = "1.45")]
487    pub use core::char::UNICODE_VERSION;
488}
489#[doc(hidden)]
490pub mod future {
491    #[cfg(reexport = "1.48")]
492    pub use core::future::{pending, ready, Pending, Ready};
493
494    #[cfg(shim = "1.48")]
495    pub use crate::free::v1_48::future::*;
496}
497#[doc(hidden)]
498pub mod array {
499    #[cfg(reexport = "1.53")]
500    pub use core::array::{from_mut, from_ref};
501
502    #[cfg(shim = "1.53")]
503    pub use crate::free::v1_53::array::*;
504}
505#[doc(hidden)]
506pub mod cmp {
507    #[cfg(reexport = "1.53")]
508    pub use core::cmp::{max_by, max_by_key, min_by, min_by_key};
509
510    #[cfg(shim = "1.53")]
511    pub use crate::free::v1_53::cmp::*;
512}
513#[doc(hidden)]
514pub mod thread {
515    #[cfg(all(feature = "std", reexport = "1.59"))]
516    pub use std::thread::available_parallelism;
517
518    #[cfg(all(feature = "std", shim = "1.59"))]
519    pub use crate::free::v1_59::available_parallelism;
520}