1 #[cfg(no_str_strip_prefix)] // rustc <1.45
2 pub(crate) trait StripPrefixExt {
strip_prefix(&self, ch: char) -> Option<&str>3     fn strip_prefix(&self, ch: char) -> Option<&str>;
4 }
5 
6 #[cfg(no_str_strip_prefix)]
7 impl StripPrefixExt for str {
strip_prefix(&self, ch: char) -> Option<&str>8     fn strip_prefix(&self, ch: char) -> Option<&str> {
9         if self.starts_with(ch) {
10             Some(&self[ch.len_utf8()..])
11         } else {
12             None
13         }
14     }
15 }
16 
17 #[cfg(no_from_ne_bytes)] // rustc <1.32
18 pub(crate) trait FromNeBytes {
from_ne_bytes(bytes: [u8; 8]) -> Self19     fn from_ne_bytes(bytes: [u8; 8]) -> Self;
20 }
21 
22 #[cfg(no_from_ne_bytes)]
23 impl FromNeBytes for u64 {
from_ne_bytes(bytes: [u8; 8]) -> Self24     fn from_ne_bytes(bytes: [u8; 8]) -> Self {
25         unsafe { std::mem::transmute(bytes) }
26     }
27 }
28 
29 pub(crate) use crate::alloc::vec::Vec;
30 
31 #[cfg(no_alloc_crate)] // rustc <1.36
32 pub(crate) mod alloc {
33     pub use std::vec;
34 
35     pub mod alloc {
36         use std::mem;
37 
38         pub struct Layout {
39             size: usize,
40         }
41 
42         impl Layout {
from_size_align_unchecked(size: usize, align: usize) -> Self43             pub unsafe fn from_size_align_unchecked(size: usize, align: usize) -> Self {
44                 assert_eq!(align, 2);
45                 Layout { size }
46             }
47         }
48 
alloc(layout: Layout) -> *mut u849         pub unsafe fn alloc(layout: Layout) -> *mut u8 {
50             let len_u16 = (layout.size + 1) / 2;
51             let mut vec = Vec::new();
52             vec.reserve_exact(len_u16);
53             let ptr: *mut u16 = vec.as_mut_ptr();
54             mem::forget(vec);
55             ptr as *mut u8
56         }
57 
dealloc(ptr: *mut u8, layout: Layout)58         pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
59             let len_u16 = (layout.size + 1) / 2;
60             unsafe { Vec::from_raw_parts(ptr as *mut u16, 0, len_u16) };
61         }
62     }
63 }
64