mirror of
https://github.com/async-rs/async-std.git
synced 2025-03-31 13:36:41 +00:00
feat: Make the utils module no_std
This commit is contained in:
parent
51b84a7620
commit
3d32fd81f4
1 changed files with 25 additions and 2 deletions
27
src/utils.rs
27
src/utils.rs
|
@ -1,3 +1,9 @@
|
||||||
|
#[cfg(feature = "no-std")]
|
||||||
|
extern crate alloc;
|
||||||
|
|
||||||
|
#[cfg(feature = "no-std")]
|
||||||
|
use alloc::string::String;
|
||||||
|
|
||||||
/// Calls a function and aborts if it panics.
|
/// Calls a function and aborts if it panics.
|
||||||
///
|
///
|
||||||
/// This is useful in unsafe code where we can't recover from panics.
|
/// This is useful in unsafe code where we can't recover from panics.
|
||||||
|
@ -104,6 +110,7 @@ macro_rules! cfg_unstable_default {
|
||||||
|
|
||||||
/// Declares Unix-specific items.
|
/// Declares Unix-specific items.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
#[allow(unused_macros)]
|
||||||
macro_rules! cfg_unix {
|
macro_rules! cfg_unix {
|
||||||
($($item:item)*) => {
|
($($item:item)*) => {
|
||||||
$(
|
$(
|
||||||
|
@ -116,6 +123,7 @@ macro_rules! cfg_unix {
|
||||||
|
|
||||||
/// Declares Windows-specific items.
|
/// Declares Windows-specific items.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
#[allow(unused_macros)]
|
||||||
macro_rules! cfg_windows {
|
macro_rules! cfg_windows {
|
||||||
($($item:item)*) => {
|
($($item:item)*) => {
|
||||||
$(
|
$(
|
||||||
|
@ -128,6 +136,7 @@ macro_rules! cfg_windows {
|
||||||
|
|
||||||
/// Declares items when the "docs" feature is enabled.
|
/// Declares items when the "docs" feature is enabled.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
#[allow(unused_macros)]
|
||||||
macro_rules! cfg_docs {
|
macro_rules! cfg_docs {
|
||||||
($($item:item)*) => {
|
($($item:item)*) => {
|
||||||
$(
|
$(
|
||||||
|
@ -139,6 +148,7 @@ macro_rules! cfg_docs {
|
||||||
|
|
||||||
/// Declares items when the "docs" feature is disabled.
|
/// Declares items when the "docs" feature is disabled.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
#[allow(unused_macros)]
|
||||||
macro_rules! cfg_not_docs {
|
macro_rules! cfg_not_docs {
|
||||||
($($item:item)*) => {
|
($($item:item)*) => {
|
||||||
$(
|
$(
|
||||||
|
@ -160,6 +170,18 @@ macro_rules! cfg_std {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Declares no-std items.
|
||||||
|
#[allow(unused_macros)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
macro_rules! cfg_no_std {
|
||||||
|
($($item:item)*) => {
|
||||||
|
$(
|
||||||
|
#[cfg(feature = "no-std")]
|
||||||
|
$item
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Declares default items.
|
/// Declares default items.
|
||||||
#[allow(unused_macros)]
|
#[allow(unused_macros)]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
@ -180,6 +202,7 @@ macro_rules! cfg_default {
|
||||||
///
|
///
|
||||||
/// Inside invocations of this macro, we write a definitions that looks similar to the final
|
/// Inside invocations of this macro, we write a definitions that looks similar to the final
|
||||||
/// rendered docs, and the macro then generates all the boilerplate for us.
|
/// rendered docs, and the macro then generates all the boilerplate for us.
|
||||||
|
#[allow(unused_macros)]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
macro_rules! extension_trait {
|
macro_rules! extension_trait {
|
||||||
(
|
(
|
||||||
|
@ -204,14 +227,14 @@ macro_rules! extension_trait {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
mod owned {
|
mod owned {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub struct ImplFuture<T>(std::marker::PhantomData<T>);
|
pub struct ImplFuture<T>(core::marker::PhantomData<T>);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A fake `impl Future` type that borrows its environment.
|
// A fake `impl Future` type that borrows its environment.
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
mod borrowed {
|
mod borrowed {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub struct ImplFuture<'a, T>(std::marker::PhantomData<&'a T>);
|
pub struct ImplFuture<'a, T>(core::marker::PhantomData<&'a T>);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render a fake trait combining the bodies of the base trait and the extension trait.
|
// Render a fake trait combining the bodies of the base trait and the extension trait.
|
||||||
|
|
Loading…
Reference in a new issue