]> git.proxmox.com Git - rustc.git/blame - vendor/serde/src/private/mod.rs
New upstream version 1.74.1+dfsg1
[rustc.git] / vendor / serde / src / private / mod.rs
CommitLineData
5099ac24 1#[cfg(not(no_serde_derive))]
041b39d2 2pub mod de;
5099ac24 3#[cfg(not(no_serde_derive))]
83c7162d 4pub mod ser;
5869c6ff 5
5869c6ff
XL
6// FIXME: #[cfg(doctest)] once https://github.com/rust-lang/rust/issues/67295 is fixed.
7pub mod doc;
8
781aab86
FG
9pub use crate::lib::clone::Clone;
10pub use crate::lib::convert::{From, Into};
11pub use crate::lib::default::Default;
12pub use crate::lib::fmt::{self, Formatter};
13pub use crate::lib::marker::PhantomData;
14pub use crate::lib::option::Option::{self, None, Some};
15pub use crate::lib::ptr;
16pub use crate::lib::result::Result::{self, Err, Ok};
5869c6ff
XL
17
18pub use self::string::from_utf8_lossy;
19
20#[cfg(any(feature = "alloc", feature = "std"))]
781aab86 21pub use crate::lib::{ToString, Vec};
5869c6ff 22
5099ac24 23#[cfg(not(no_core_try_from))]
781aab86 24pub use crate::lib::convert::TryFrom;
5869c6ff
XL
25
26mod 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}