blob: e896902360ba2fd73aeea77ad8c6b75e50194b28 [file] [log] [blame]
David LeGared1bc1012022-03-02 16:21:24 +00001#[cfg(not(no_serde_derive))]
Yi Konge94f3922020-08-31 01:24:17 +08002pub mod de;
David LeGared1bc1012022-03-02 16:21:24 +00003#[cfg(not(no_serde_derive))]
Yi Konge94f3922020-08-31 01:24:17 +08004pub mod ser;
Haibo Huangfbee95b2021-01-11 19:32:29 -08005
Haibo Huangb3085842021-02-09 17:58:09 -08006pub mod size_hint;
7
8// FIXME: #[cfg(doctest)] once https://github.com/rust-lang/rust/issues/67295 is fixed.
9pub mod doc;
10
Haibo Huangfbee95b2021-01-11 19:32:29 -080011pub use lib::clone::Clone;
12pub use lib::convert::{From, Into};
13pub use lib::default::Default;
14pub use lib::fmt::{self, Formatter};
15pub use lib::marker::PhantomData;
16pub use lib::option::Option::{self, None, Some};
Joel Galensonda48ce92021-09-22 11:17:22 -070017pub use lib::ptr;
Haibo Huangfbee95b2021-01-11 19:32:29 -080018pub use lib::result::Result::{self, Err, Ok};
19
20pub use self::string::from_utf8_lossy;
21
22#[cfg(any(feature = "alloc", feature = "std"))]
23pub use lib::{ToString, Vec};
24
David LeGared1bc1012022-03-02 16:21:24 +000025#[cfg(not(no_core_try_from))]
Haibo Huangfbee95b2021-01-11 19:32:29 -080026pub use lib::convert::TryFrom;
27
28mod string {
29 use lib::*;
30
31 #[cfg(any(feature = "std", feature = "alloc"))]
32 pub fn from_utf8_lossy(bytes: &[u8]) -> Cow<str> {
33 String::from_utf8_lossy(bytes)
34 }
35
36 // The generated code calls this like:
37 //
38 // let value = &_serde::__private::from_utf8_lossy(bytes);
39 // Err(_serde::de::Error::unknown_variant(value, VARIANTS))
40 //
41 // so it is okay for the return type to be different from the std case as long
42 // as the above works.
43 #[cfg(not(any(feature = "std", feature = "alloc")))]
44 pub fn from_utf8_lossy(bytes: &[u8]) -> &str {
45 // Three unicode replacement characters if it fails. They look like a
46 // white-on-black question mark. The user will recognize it as invalid
47 // UTF-8.
48 str::from_utf8(bytes).unwrap_or("\u{fffd}\u{fffd}\u{fffd}")
49 }
50}