]> git.proxmox.com Git - rustc.git/blame - src/vendor/serde-0.9.15/src/export.rs
New upstream version 1.19.0+dfsg3
[rustc.git] / src / vendor / serde-0.9.15 / src / export.rs
CommitLineData
7cac9316
XL
1#[cfg(all(feature = "collections", not(feature = "std")))]
2use collections::String;
3
4#[cfg(feature = "std")]
5use std::borrow::Cow;
6#[cfg(all(feature = "collections", not(feature = "std")))]
7use collections::borrow::Cow;
8
9pub use core::clone::Clone;
10pub use core::convert::{From, Into};
11pub use core::default::Default;
12pub use core::fmt;
13pub use core::marker::PhantomData;
14pub use core::option::Option::{self, None, Some};
15pub use core::result::Result::{self, Ok, Err};
16
17#[cfg(any(feature = "collections", feature = "std"))]
18pub fn from_utf8_lossy(bytes: &[u8]) -> Cow<str> {
19 String::from_utf8_lossy(bytes)
20}
21
22// The generated code calls this like:
23//
24// let value = &_serde::export::from_utf8_lossy(bytes);
25// Err(_serde::de::Error::unknown_variant(value, VARIANTS))
26//
27// so it is okay for the return type to be different from the std case as long
28// as the above works.
29#[cfg(not(any(feature = "collections", feature = "std")))]
30pub fn from_utf8_lossy(bytes: &[u8]) -> &str {
31 use core::str;
32 // Three unicode replacement characters if it fails. They look like a
33 // white-on-black question mark. The user will recognize it as invalid
34 // UTF-8.
35 str::from_utf8(bytes).unwrap_or("\u{fffd}\u{fffd}\u{fffd}")
36}