serde/
export.rs

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