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