Skip to content
Myr

crate_root.rs

This file

Path

serde_core/src/crate_root.rs

171 lines · 6.9 KiB · Rust

Last changed by

Merge pull request #2995 from dtolnay/rustdocflagsDavid Tolnaybefore adoption5adc9e8

History of this file

Take it

1macro_rules! crate_root {2    () => {3        /// A facade around all the types we need from the `std`, `core`, and `alloc`4        /// crates. This avoids elaborate import wrangling having to happen in every5        /// module.6        mod lib {7            mod core {8                #[cfg(not(feature = "std"))]9                pub use core::*;10                #[cfg(feature = "std")]11                pub use std::*;12            }1314            pub use self::core::{f32, f64};15            pub use self::core::{iter, num, str};1617            #[cfg(any(feature = "std", feature = "alloc"))]18            pub use self::core::{cmp, mem};1920            pub use self::core::cell::{Cell, RefCell};21            pub use self::core::cmp::Reverse;22            pub use self::core::fmt::{self, Debug, Display, Write as FmtWrite};23            pub use self::core::marker::PhantomData;24            pub use self::core::num::Wrapping;25            pub use self::core::ops::{Bound, Range, RangeFrom, RangeInclusive, RangeTo};26            pub use self::core::result;27            pub use self::core::time::Duration;2829            #[cfg(all(feature = "alloc", not(feature = "std")))]30            pub use alloc::borrow::{Cow, ToOwned};31            #[cfg(feature = "std")]32            pub use std::borrow::{Cow, ToOwned};3334            #[cfg(all(feature = "alloc", not(feature = "std")))]35            pub use alloc::string::{String, ToString};36            #[cfg(feature = "std")]37            pub use std::string::{String, ToString};3839            #[cfg(all(feature = "alloc", not(feature = "std")))]40            pub use alloc::vec::Vec;41            #[cfg(feature = "std")]42            pub use std::vec::Vec;4344            #[cfg(all(feature = "alloc", not(feature = "std")))]45            pub use alloc::boxed::Box;46            #[cfg(feature = "std")]47            pub use std::boxed::Box;4849            #[cfg(all(feature = "rc", feature = "alloc", not(feature = "std")))]50            pub use alloc::rc::{Rc, Weak as RcWeak};51            #[cfg(all(feature = "rc", feature = "std"))]52            pub use std::rc::{Rc, Weak as RcWeak};5354            #[cfg(all(feature = "rc", feature = "alloc", not(feature = "std")))]55            pub use alloc::sync::{Arc, Weak as ArcWeak};56            #[cfg(all(feature = "rc", feature = "std"))]57            pub use std::sync::{Arc, Weak as ArcWeak};5859            #[cfg(all(feature = "alloc", not(feature = "std")))]60            pub use alloc::collections::{BTreeMap, BTreeSet, BinaryHeap, LinkedList, VecDeque};61            #[cfg(feature = "std")]62            pub use std::collections::{BTreeMap, BTreeSet, BinaryHeap, LinkedList, VecDeque};6364            #[cfg(all(not(no_core_cstr), not(feature = "std")))]65            pub use self::core::ffi::CStr;66            #[cfg(feature = "std")]67            pub use std::ffi::CStr;6869            #[cfg(all(not(no_core_cstr), feature = "alloc", not(feature = "std")))]70            pub use alloc::ffi::CString;71            #[cfg(feature = "std")]72            pub use std::ffi::CString;7374            #[cfg(all(not(no_core_net), not(feature = "std")))]75            pub use self::core::net;76            #[cfg(feature = "std")]77            pub use std::net;7879            #[cfg(feature = "std")]80            pub use std::error;8182            #[cfg(feature = "std")]83            pub use std::collections::{HashMap, HashSet};84            #[cfg(feature = "std")]85            pub use std::ffi::{OsStr, OsString};86            #[cfg(feature = "std")]87            pub use std::hash::{BuildHasher, Hash};88            #[cfg(feature = "std")]89            pub use std::io::Write;90            #[cfg(feature = "std")]91            pub use std::path::{Path, PathBuf};92            #[cfg(feature = "std")]93            pub use std::sync::{Mutex, RwLock};94            #[cfg(feature = "std")]95            pub use std::time::{SystemTime, UNIX_EPOCH};9697            #[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic)))]98            pub use std::sync::atomic::{99                AtomicBool, AtomicI16, AtomicI32, AtomicI8, AtomicIsize, AtomicU16, AtomicU32,100                AtomicU8, AtomicUsize, Ordering,101            };102            #[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic64)))]103            pub use std::sync::atomic::{AtomicI64, AtomicU64};104105            #[cfg(all(feature = "std", not(no_target_has_atomic)))]106            pub use std::sync::atomic::Ordering;107            #[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "8"))]108            pub use std::sync::atomic::{AtomicBool, AtomicI8, AtomicU8};109            #[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "16"))]110            pub use std::sync::atomic::{AtomicI16, AtomicU16};111            #[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "32"))]112            pub use std::sync::atomic::{AtomicI32, AtomicU32};113            #[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "64"))]114            pub use std::sync::atomic::{AtomicI64, AtomicU64};115            #[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "ptr"))]116            pub use std::sync::atomic::{AtomicIsize, AtomicUsize};117118            #[cfg(not(no_core_num_saturating))]119            pub use self::core::num::Saturating;120        }121122        // None of this crate's error handling needs the `From::from` error conversion123        // performed implicitly by the `?` operator or the standard library's `try!`124        // macro. This simplified macro gives a 5.5% improvement in compile time125        // compared to standard `try!`, and 9% improvement compared to `?`.126        macro_rules! tri {127            ($expr:expr) => {128                match $expr {129                    Ok(val) => val,130                    Err(err) => return Err(err),131                }132            };133        }134135        #[cfg_attr(all(docsrs, if_docsrs_then_no_serde_core), path = "core/de/mod.rs")]136        pub mod de;137        #[cfg_attr(all(docsrs, if_docsrs_then_no_serde_core), path = "core/ser/mod.rs")]138        pub mod ser;139140        #[cfg_attr(all(docsrs, if_docsrs_then_no_serde_core), path = "core/format.rs")]141        mod format;142143        #[doc(inline)]144        pub use crate::de::{Deserialize, Deserializer};145        #[doc(inline)]146        pub use crate::ser::{Serialize, Serializer};147148        // Used by generated code. Not public API.149        #[doc(hidden)]150        #[cfg_attr(151            all(docsrs, if_docsrs_then_no_serde_core),152            path = "core/private/mod.rs"153        )]154        mod private;155156        // Used by declarative macro generated code. Not public API.157        #[doc(hidden)]158        pub mod __private {159            #[doc(hidden)]160            pub use crate::private::doc;161            #[doc(hidden)]162            pub use core::result::Result;163        }164165        include!(concat!(env!("OUT_DIR"), "/private.rs"));166167        #[cfg(all(not(feature = "std"), no_core_error))]168        #[cfg_attr(all(docsrs, if_docsrs_then_no_serde_core), path = "core/std_error.rs")]169        mod std_error;170    };171}