compat_no_std/
lib.rs

1#![no_std]
2#![cfg_attr(all(not(feature = "std"), feature = "unstable"),
3            feature(core_intrinsics, core_panic, once_cell, raw, unicode_internals, async_stream))]
4#![cfg_attr(all(not(feature = "std"), feature = "alloc", feature = "unstable"),
5            feature(alloc_prelude, raw_vec_internals))]
6#![cfg_attr(all(not(feature = "std"), feature = "alloc", feature = "unstable", not(target_os = "none")),
7            feature(wake_trait))]
8
9// Can't use cfg_if! because it does not allow nesting :(
10
11// Actually, can't even generate #[cfg]s any other way because of
12// https://github.com/rust-lang/rust/pull/52234#issuecomment-486810130
13
14// if #[cfg(feature = "std")] {
15    #[cfg(feature = "std")]
16    extern crate std;
17    #[cfg(feature = "std")]
18    pub mod prelude {
19        pub mod v1 {
20            pub use std::prelude::v1::*;
21            // Macros aren't included in the prelude for some reason
22            pub use std::{
23                format, vec,
24                print, println, eprint, eprintln, dbg
25            };
26        }
27    }
28    #[cfg(feature = "std")]
29    pub use std::*;
30// } else {
31    // The 2 underscores in the crate names are used to avoid
32    // ambiguity between whether the user wants to use the public
33    // module std::alloc or the private crate no_std_compat::alloc
34    // (see https://gitlab.com/jD91mZM2/no-std-compat/issues/1)
35
36    // if #[cfg(feature = "alloc")] {
37        #[cfg(all(not(feature = "std"), feature = "alloc"))]
38        extern crate alloc as __alloc;
39    // }
40
41    #[cfg(not(feature = "std"))]
42    extern crate core as __core;
43
44    #[cfg(not(feature = "std"))]
45    mod generated;
46
47    #[cfg(not(feature = "std"))]
48    pub use self::generated::*;
49
50    // if #[cfg(feature = "compat_macros")] {
51        #[cfg(all(not(feature = "std"), feature = "compat_macros"))]
52        #[macro_export]
53        macro_rules! print {
54            () => {{}};
55            ($($arg:tt)+) => {{
56                // Avoid unused arguments complaint. This surely must get
57                // optimized away? TODO: Verify that
58                let _ = format_args!($($arg)+);
59            }};
60        }
61        #[cfg(all(not(feature = "std"), feature = "compat_macros"))]
62        #[macro_export]
63        macro_rules! println {
64            ($($arg:tt)*) => { print!($($arg)*) }
65        }
66        #[cfg(all(not(feature = "std"), feature = "compat_macros"))]
67        #[macro_export]
68        macro_rules! eprint {
69            ($($arg:tt)*) => { print!($($arg)*) }
70        }
71        #[cfg(all(not(feature = "std"), feature = "compat_macros"))]
72        #[macro_export]
73        macro_rules! eprintln {
74            ($($arg:tt)*) => { print!($($arg)*) }
75        }
76
77        #[cfg(all(not(feature = "std"), feature = "compat_macros"))]
78        #[macro_export]
79        macro_rules! dbg {
80            () => {};
81            ($($val:expr),+) => { ($($val),+) }
82        }
83    // }
84// }