1 #[cfg(not(no_serde_derive))]
2 pub mod de;
3 #[cfg(not(no_serde_derive))]
4 pub mod ser;
5 
6 // FIXME: #[cfg(doctest)] once https://github.com/rust-lang/rust/issues/67295 is fixed.
7 pub mod doc;
8 
9 pub use crate::lib::clone::Clone;
10 pub use crate::lib::convert::{From, Into};
11 pub use crate::lib::default::Default;
12 pub use crate::lib::fmt::{self, Formatter};
13 pub use crate::lib::marker::PhantomData;
14 pub use crate::lib::option::Option::{self, None, Some};
15 pub use crate::lib::ptr;
16 pub use crate::lib::result::Result::{self, Err, Ok};
17 
18 pub use self::string::from_utf8_lossy;
19 
20 #[cfg(any(feature = "alloc", feature = "std"))]
21 pub use crate::lib::{ToString, Vec};
22 
23 #[cfg(not(no_core_try_from))]
24 pub use crate::lib::convert::TryFrom;
25 
26 mod string {
27     use crate::lib::*;
28 
29     #[cfg(any(feature = "std", feature = "alloc"))]
from_utf8_lossy(bytes: &[u8]) -> Cow<str>30     pub fn from_utf8_lossy(bytes: &[u8]) -> Cow<str> {
31         String::from_utf8_lossy(bytes)
32     }
33 
34     // The generated code calls this like:
35     //
36     //     let value = &_serde::__private::from_utf8_lossy(bytes);
37     //     Err(_serde::de::Error::unknown_variant(value, VARIANTS))
38     //
39     // so it is okay for the return type to be different from the std case as long
40     // as the above works.
41     #[cfg(not(any(feature = "std", feature = "alloc")))]
from_utf8_lossy(bytes: &[u8]) -> &str42     pub fn from_utf8_lossy(bytes: &[u8]) -> &str {
43         // Three unicode replacement characters if it fails. They look like a
44         // white-on-black question mark. The user will recognize it as invalid
45         // UTF-8.
46         str::from_utf8(bytes).unwrap_or("\u{fffd}\u{fffd}\u{fffd}")
47     }
48 }
49