1 pub use lib::clone::Clone; 2 pub use lib::convert::{From, Into}; 3 pub use lib::default::Default; 4 pub use lib::fmt::{self, Formatter}; 5 pub use lib::marker::PhantomData; 6 pub use lib::option::Option::{self, None, Some}; 7 pub use lib::result::Result::{self, Err, Ok}; 8 9 pub use self::string::from_utf8_lossy; 10 11 #[cfg(any(feature = "alloc", feature = "std"))] 12 pub use lib::{ToString, Vec}; 13 14 #[cfg(core_try_from)] 15 pub use lib::convert::TryFrom; 16 17 mod string { 18 use lib::*; 19 20 #[cfg(any(feature = "std", feature = "alloc"))] from_utf8_lossy(bytes: &[u8]) -> Cow<str>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")))] from_utf8_lossy(bytes: &[u8]) -> &str33 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 } 40