]>
git.proxmox.com Git - rustc.git/blob - src/vendor/serde/src/export.rs
1 // Copyright 2017 Serde Developers
3 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6 // option. This file may not be copied, modified, or distributed
7 // except according to those terms.
9 pub use lib
::clone
::Clone
;
10 pub use lib
::convert
::{From, Into}
;
11 pub use lib
::default::Default
;
12 pub use lib
::fmt
::{self, Formatter}
;
13 pub use lib
::marker
::PhantomData
;
14 pub use lib
::option
::Option
::{self, None, Some}
;
15 pub use lib
::result
::Result
::{self, Err, Ok}
;
17 pub use self::string
::from_utf8_lossy
;
22 #[cfg(any(feature = "std", feature = "alloc"))]
23 pub fn from_utf8_lossy(bytes
: &[u8]) -> Cow
<str> {
24 String
::from_utf8_lossy(bytes
)
27 // The generated code calls this like:
29 // let value = &_serde::export::from_utf8_lossy(bytes);
30 // Err(_serde::de::Error::unknown_variant(value, VARIANTS))
32 // so it is okay for the return type to be different from the std case as long
33 // as the above works.
34 #[cfg(not(any(feature = "std", feature = "alloc")))]
35 pub fn from_utf8_lossy(bytes
: &[u8]) -> &str {
36 // Three unicode replacement characters if it fails. They look like a
37 // white-on-black question mark. The user will recognize it as invalid
39 str::from_utf8(bytes
).unwrap_or("\u{fffd}\u{fffd}\u{fffd}")