]>
Commit | Line | Data |
---|---|---|
5099ac24 | 1 | #[cfg(not(no_serde_derive))] |
041b39d2 | 2 | pub mod de; |
5099ac24 | 3 | #[cfg(not(no_serde_derive))] |
83c7162d | 4 | pub mod ser; |
5869c6ff | 5 | |
5869c6ff XL |
6 | // FIXME: #[cfg(doctest)] once https://github.com/rust-lang/rust/issues/67295 is fixed. |
7 | pub mod doc; | |
8 | ||
781aab86 FG |
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}; | |
5869c6ff XL |
17 | |
18 | pub use self::string::from_utf8_lossy; | |
19 | ||
20 | #[cfg(any(feature = "alloc", feature = "std"))] | |
781aab86 | 21 | pub use crate::lib::{ToString, Vec}; |
5869c6ff | 22 | |
5099ac24 | 23 | #[cfg(not(no_core_try_from))] |
781aab86 | 24 | pub use crate::lib::convert::TryFrom; |
5869c6ff XL |
25 | |
26 | mod string { | |
781aab86 | 27 | use crate::lib::*; |
5869c6ff XL |
28 | |
29 | #[cfg(any(feature = "std", feature = "alloc"))] | |
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")))] | |
42 | 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 | } |