mirror of
https://github.com/serde-rs/serde.git
synced 2025-10-02 23:35:26 +00:00
Appease Rust 1.13.0
This commit is contained in:
parent
f88db0f547
commit
2efb95015b
@ -1,5 +1,3 @@
|
|||||||
use lib::*;
|
|
||||||
|
|
||||||
pub use lib::clone::Clone;
|
pub use lib::clone::Clone;
|
||||||
pub use lib::convert::{From, Into};
|
pub use lib::convert::{From, Into};
|
||||||
pub use lib::default::Default;
|
pub use lib::default::Default;
|
||||||
@ -8,22 +6,28 @@ pub use lib::marker::PhantomData;
|
|||||||
pub use lib::option::Option::{self, None, Some};
|
pub use lib::option::Option::{self, None, Some};
|
||||||
pub use lib::result::Result::{self, Ok, Err};
|
pub use lib::result::Result::{self, Ok, Err};
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
pub use self::string::from_utf8_lossy;
|
||||||
pub fn from_utf8_lossy(bytes: &[u8]) -> Cow<str> {
|
|
||||||
String::from_utf8_lossy(bytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
// The generated code calls this like:
|
mod string {
|
||||||
//
|
use lib::*;
|
||||||
// let value = &_serde::export::from_utf8_lossy(bytes);
|
|
||||||
// Err(_serde::de::Error::unknown_variant(value, VARIANTS))
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
//
|
pub fn from_utf8_lossy(bytes: &[u8]) -> Cow<str> {
|
||||||
// so it is okay for the return type to be different from the std case as long
|
String::from_utf8_lossy(bytes)
|
||||||
// as the above works.
|
}
|
||||||
#[cfg(not(any(feature = "std", feature = "collections")))]
|
|
||||||
pub fn from_utf8_lossy(bytes: &[u8]) -> &str {
|
// The generated code calls this like:
|
||||||
// Three unicode replacement characters if it fails. They look like a
|
//
|
||||||
// white-on-black question mark. The user will recognize it as invalid
|
// let value = &_serde::export::from_utf8_lossy(bytes);
|
||||||
// UTF-8.
|
// Err(_serde::de::Error::unknown_variant(value, VARIANTS))
|
||||||
str::from_utf8(bytes).unwrap_or("\u{fffd}\u{fffd}\u{fffd}")
|
//
|
||||||
|
// so it is okay for the return type to be different from the std case as long
|
||||||
|
// as the above works.
|
||||||
|
#[cfg(not(any(feature = "std", feature = "collections")))]
|
||||||
|
pub fn from_utf8_lossy(bytes: &[u8]) -> &str {
|
||||||
|
// Three unicode replacement characters if it fails. They look like a
|
||||||
|
// white-on-black question mark. The user will recognize it as invalid
|
||||||
|
// UTF-8.
|
||||||
|
str::from_utf8(bytes).unwrap_or("\u{fffd}\u{fffd}\u{fffd}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,10 +81,12 @@ extern crate core;
|
|||||||
/// `collections` crates. This avoids elaborate import wrangling having to
|
/// `collections` crates. This avoids elaborate import wrangling having to
|
||||||
/// happen in every module.
|
/// happen in every module.
|
||||||
mod lib {
|
mod lib {
|
||||||
#[cfg(feature = "std")]
|
mod core {
|
||||||
use std as core;
|
#[cfg(feature = "std")]
|
||||||
#[cfg(not(feature = "std"))]
|
pub use std::*;
|
||||||
use core;
|
#[cfg(not(feature = "std"))]
|
||||||
|
pub use core::*;
|
||||||
|
}
|
||||||
|
|
||||||
pub use self::core::{cmp, iter, mem, ops, str};
|
pub use self::core::{cmp, iter, mem, ops, str};
|
||||||
pub use self::core::{i8, i16, i32, i64, isize};
|
pub use self::core::{i8, i16, i32, i64, isize};
|
||||||
|
@ -866,7 +866,7 @@ pub trait Serializer: Sized {
|
|||||||
fn collect_str<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error>
|
fn collect_str<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error>
|
||||||
where T: Display
|
where T: Display
|
||||||
{
|
{
|
||||||
use self::fmt::Write;
|
use lib::fmt::Write;
|
||||||
let mut string = String::new();
|
let mut string = String::new();
|
||||||
write!(string, "{}", value).unwrap();
|
write!(string, "{}", value).unwrap();
|
||||||
self.serialize_str(&string)
|
self.serialize_str(&string)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user