| 1 | //! Re-exports either the Rust `std` library or `core` and `alloc` when `std` is | 
| 2 | //! disabled. | 
|---|
| 3 | //! | 
|---|
| 4 | //! `crate::stdlib::...` should be used rather than `std::` when adding code that | 
|---|
| 5 | //! will be available with the standard library disabled. | 
|---|
| 6 | //! | 
|---|
| 7 | //! Note that this module is called `stdlib` rather than `std`, as Rust 1.34.0 | 
|---|
| 8 | //! does not permit redefining the name `stdlib` (although this works on the | 
|---|
| 9 | //! latest stable Rust). | 
|---|
| 10 | #[ cfg(feature = "std")] | 
|---|
| 11 | pub(crate) use std::*; | 
|---|
| 12 |  | 
|---|
| 13 | #[ cfg(not(feature = "std"))] | 
|---|
| 14 | pub(crate) use self::no_std::*; | 
|---|
| 15 |  | 
|---|
| 16 | #[ cfg(not(feature = "std"))] | 
|---|
| 17 | mod no_std { | 
|---|
| 18 | // We pre-emptively export everything from libcore/liballoc, (even modules | 
|---|
| 19 | // we aren't using currently) to make adding new code easier. Therefore, | 
|---|
| 20 | // some of these imports will be unused. | 
|---|
| 21 | #![ allow(unused_imports)] | 
|---|
| 22 |  | 
|---|
| 23 | pub(crate) use core::{ | 
|---|
| 24 | any, array, ascii, cell, char, clone, cmp, convert, default, f32, f64, ffi, future, hash, | 
|---|
| 25 | hint, i128, i16, i8, isize, iter, marker, mem, num, ops, option, pin, ptr, result, task, | 
|---|
| 26 | time, u128, u16, u32, u8, usize, | 
|---|
| 27 | }; | 
|---|
| 28 |  | 
|---|
| 29 | pub(crate) use alloc::{boxed, collections, rc, string, vec}; | 
|---|
| 30 |  | 
|---|
| 31 | pub(crate) mod borrow { | 
|---|
| 32 | pub(crate) use alloc::borrow::*; | 
|---|
| 33 | pub(crate) use core::borrow::*; | 
|---|
| 34 | } | 
|---|
| 35 |  | 
|---|
| 36 | pub(crate) mod fmt { | 
|---|
| 37 | pub(crate) use alloc::fmt::*; | 
|---|
| 38 | pub(crate) use core::fmt::*; | 
|---|
| 39 | } | 
|---|
| 40 |  | 
|---|
| 41 | pub(crate) mod slice { | 
|---|
| 42 | pub(crate) use alloc::slice::*; | 
|---|
| 43 | pub(crate) use core::slice::*; | 
|---|
| 44 | } | 
|---|
| 45 |  | 
|---|
| 46 | pub(crate) mod str { | 
|---|
| 47 | pub(crate) use alloc::str::*; | 
|---|
| 48 | pub(crate) use core::str::*; | 
|---|
| 49 | } | 
|---|
| 50 |  | 
|---|
| 51 | pub(crate) mod sync { | 
|---|
| 52 | pub(crate) use crate::spin::MutexGuard; | 
|---|
| 53 | pub(crate) use alloc::sync::*; | 
|---|
| 54 | pub(crate) use core::sync::*; | 
|---|
| 55 |  | 
|---|
| 56 | /// This wraps `spin::Mutex` to return a `Result`, so that it can be | 
|---|
| 57 | /// used with code written against `std::sync::Mutex`. | 
|---|
| 58 | /// | 
|---|
| 59 | /// Since `spin::Mutex` doesn't support poisoning, the `Result` returned | 
|---|
| 60 | /// by `lock` will always be `Ok`. | 
|---|
| 61 | #[ derive(Debug, Default)] | 
|---|
| 62 | pub(crate) struct Mutex<T> { | 
|---|
| 63 | inner: crate::spin::Mutex<T>, | 
|---|
| 64 | } | 
|---|
| 65 |  | 
|---|
| 66 | impl<T> Mutex<T> { | 
|---|
| 67 | // pub(crate) fn new(data: T) -> Self { | 
|---|
| 68 | //     Self { | 
|---|
| 69 | //         inner: crate::spin::Mutex::new(data), | 
|---|
| 70 | //     } | 
|---|
| 71 | // } | 
|---|
| 72 |  | 
|---|
| 73 | pub(crate) fn lock(&self) -> Result<MutexGuard<'_, T>, ()> { | 
|---|
| 74 | Ok(self.inner.lock()) | 
|---|
| 75 | } | 
|---|
| 76 | } | 
|---|
| 77 | } | 
|---|
| 78 | } | 
|---|
| 79 |  | 
|---|