Skip to main content

serde_private/
lib.rs

1////////////////////////////////////////////////////////////////////////////////
2
3// Serde types in rustdoc of other crates get linked to here.
4#![doc(html_root_url = "https://docs.rs/serde/1.0.225")]
5// Support using Serde without the standard library!
6#![cfg_attr(not(feature = "std"), no_std)]
7// Show which crate feature enables conditionally compiled APIs in documentation.
8#![cfg_attr(docsrs, feature(doc_cfg, rustdoc_internals))]
9#![cfg_attr(docsrs, allow(internal_features))]
10// Unstable functionality only if the user asks for it. For tracking and
11// discussion of these features please refer to this issue:
12//
13//    https://github.com/serde-rs/serde/issues/812
14#![cfg_attr(feature = "unstable", feature(never_type))]
15#![allow(
16    unknown_lints,
17    bare_trait_objects,
18    deprecated,
19    mismatched_lifetime_syntaxes
20)]
21// Ignored clippy and clippy_pedantic lints
22#![allow(
23    // clippy bug: https://github.com/rust-lang/rust-clippy/issues/5704
24    clippy::unnested_or_patterns,
25    // clippy bug: https://github.com/rust-lang/rust-clippy/issues/7768
26    clippy::semicolon_if_nothing_returned,
27    // not available in our oldest supported compiler
28    clippy::empty_enum,
29    clippy::type_repetition_in_bounds, // https://github.com/rust-lang/rust-clippy/issues/8772
30    // integer and float ser/de requires these sorts of casts
31    clippy::cast_possible_truncation,
32    clippy::cast_possible_wrap,
33    clippy::cast_precision_loss,
34    clippy::cast_sign_loss,
35    // things are often more readable this way
36    clippy::cast_lossless,
37    clippy::module_name_repetitions,
38    clippy::single_match_else,
39    clippy::type_complexity,
40    clippy::use_self,
41    clippy::zero_prefixed_literal,
42    // correctly used
43    clippy::derive_partial_eq_without_eq,
44    clippy::enum_glob_use,
45    clippy::explicit_auto_deref,
46    clippy::incompatible_msrv,
47    clippy::let_underscore_untyped,
48    clippy::map_err_ignore,
49    clippy::new_without_default,
50    clippy::result_unit_err,
51    clippy::wildcard_imports,
52    // not practical
53    clippy::needless_pass_by_value,
54    clippy::similar_names,
55    clippy::too_many_lines,
56    // preference
57    clippy::doc_markdown,
58    clippy::elidable_lifetime_names,
59    clippy::needless_lifetimes,
60    clippy::unseparated_literal_suffix,
61    // false positive
62    clippy::needless_doctest_main,
63    // noisy
64    clippy::missing_errors_doc,
65    clippy::must_use_candidate,
66)]
67// Restrictions
68#![deny(clippy::question_mark_used)]
69// Rustc lints.
70#![allow(missing_docs)]
71
72////////////////////////////////////////////////////////////////////////////////
73
74#[cfg(feature = "alloc")]
75extern crate alloc;
76
77/// A facade around all the types we need from the `std`, `core`, and `alloc`
78/// crates. This avoids elaborate import wrangling having to happen in every
79/// module.
80mod lib {
81    #![allow(unused_imports)]
82    mod core {
83        #[cfg(not(feature = "std"))]
84        pub use core::*;
85        #[cfg(feature = "std")]
86        pub use std::*;
87    }
88
89    pub use self::core::{f32, f64};
90    pub use self::core::{ptr, str};
91
92    #[cfg(any(feature = "std", feature = "alloc"))]
93    pub use self::core::slice;
94
95    pub use self::core::clone;
96    pub use self::core::convert;
97    pub use self::core::default;
98    pub use self::core::fmt::{self, Debug, Display, Write as FmtWrite};
99    pub use self::core::marker::{self, PhantomData};
100    pub use self::core::option;
101    pub use self::core::result;
102
103    pub use self::core::mem;
104
105    #[cfg(all(feature = "alloc", not(feature = "std")))]
106    pub use alloc::borrow::{Cow, ToOwned};
107    #[cfg(feature = "std")]
108    pub use std::borrow::{Cow, ToOwned};
109
110    #[cfg(all(feature = "alloc", not(feature = "std")))]
111    pub use alloc::string::{String, ToString};
112    #[cfg(feature = "std")]
113    pub use std::string::{String, ToString};
114
115    #[cfg(all(feature = "alloc", not(feature = "std")))]
116    pub use alloc::vec::Vec;
117    #[cfg(feature = "std")]
118    pub use std::vec::Vec;
119
120    #[cfg(all(feature = "alloc", not(feature = "std")))]
121    pub use alloc::boxed::Box;
122    #[cfg(feature = "std")]
123    pub use std::boxed::Box;
124}
125
126// None of this crate's error handling needs the `From::from` error conversion
127// performed implicitly by the `?` operator or the standard library's `try!`
128// macro. This simplified macro gives a 5.5% improvement in compile time
129// compared to standard `try!`, and 9% improvement compared to `?`.
130#[cfg(not(no_serde_derive))]
131macro_rules! tri {
132    ($expr:expr) => {
133        match $expr {
134            Ok(val) => val,
135            Err(err) => return Err(err),
136        }
137    };
138}
139
140////////////////////////////////////////////////////////////////////////////////
141
142// pub use serde_core::{
143//     de, forward_to_deserialize_any, ser, Deserialize, Deserializer, Serialize, Serializer,
144// };
145
146// #[macro_use]
147// mod integer128;
148
149// Used by generated code and doc tests. Not public API.
150mod private;
151
152pub use private::*;
153
154use serde_core::de as __de;
155use serde_core::ser as __ser;
156
157// include!(concat!(env!("OUT_DIR"), "/private.rs"));
158
159// Re-export #[derive(Serialize, Deserialize)].
160//
161// The reason re-exporting is not enabled by default is that disabling it would
162// be annoying for crates that provide handwritten impls or data formats. They
163// would need to disable default features and then explicitly re-enable std.
164// #[cfg(feature = "serde_derive")]
165// extern crate serde_derive;
166
167// /// Derive macro available if serde is built with `features = ["derive"]`.
168// #[cfg(feature = "serde_derive")]
169// #[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
170// pub use serde_derive::{Deserialize, Serialize};
171
172// #[macro_export]
173// #[doc(hidden)]
174// macro_rules! __require_serde_not_serde_core {
175//     () => {};
176// }
177
178use serde_private_core as serde_core_private;