mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-17 12:41:02 +00:00
Make from_utf8_lossy private
This commit is contained in:
@@ -15,11 +15,7 @@ pub use crate::lib::option::Option::{self, None, Some};
|
|||||||
pub use crate::lib::ptr;
|
pub use crate::lib::ptr;
|
||||||
pub use crate::lib::result::Result::{self, Err, Ok};
|
pub use crate::lib::result::Result::{self, Err, Ok};
|
||||||
|
|
||||||
pub use self::string::from_utf8_lossy;
|
pub use serde_core::__private::string::from_utf8_lossy;
|
||||||
|
|
||||||
#[cfg(any(feature = "alloc", feature = "std"))]
|
#[cfg(any(feature = "alloc", feature = "std"))]
|
||||||
pub use crate::lib::{ToString, Vec};
|
pub use crate::lib::{ToString, Vec};
|
||||||
|
|
||||||
mod string {
|
|
||||||
pub use serde_core::from_utf8_lossy;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use crate::de::{
|
|||||||
Deserialize, Deserializer, EnumAccess, Error, MapAccess, SeqAccess, Unexpected, VariantAccess,
|
Deserialize, Deserializer, EnumAccess, Error, MapAccess, SeqAccess, Unexpected, VariantAccess,
|
||||||
Visitor,
|
Visitor,
|
||||||
};
|
};
|
||||||
|
use crate::private;
|
||||||
use crate::seed::InPlaceSeed;
|
use crate::seed::InPlaceSeed;
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
@@ -2174,7 +2174,7 @@ impl<'de> Deserialize<'de> for Duration {
|
|||||||
b"secs" => Ok(Field::Secs),
|
b"secs" => Ok(Field::Secs),
|
||||||
b"nanos" => Ok(Field::Nanos),
|
b"nanos" => Ok(Field::Nanos),
|
||||||
_ => {
|
_ => {
|
||||||
let value = crate::lib::from_utf8_lossy(value);
|
let value = private::string::from_utf8_lossy(value);
|
||||||
Err(Error::unknown_field(&*value, FIELDS))
|
Err(Error::unknown_field(&*value, FIELDS))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2465,6 +2465,7 @@ mod range {
|
|||||||
use crate::lib::*;
|
use crate::lib::*;
|
||||||
|
|
||||||
use crate::de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
|
use crate::de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
|
||||||
|
use crate::private;
|
||||||
|
|
||||||
pub const FIELDS: &[&str] = &["start", "end"];
|
pub const FIELDS: &[&str] = &["start", "end"];
|
||||||
|
|
||||||
@@ -2510,7 +2511,7 @@ mod range {
|
|||||||
b"start" => Ok(Field::Start),
|
b"start" => Ok(Field::Start),
|
||||||
b"end" => Ok(Field::End),
|
b"end" => Ok(Field::End),
|
||||||
_ => {
|
_ => {
|
||||||
let value = crate::lib::from_utf8_lossy(value);
|
let value = private::string::from_utf8_lossy(value);
|
||||||
Err(Error::unknown_field(&*value, FIELDS))
|
Err(Error::unknown_field(&*value, FIELDS))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2623,6 +2624,7 @@ mod range_from {
|
|||||||
use crate::lib::*;
|
use crate::lib::*;
|
||||||
|
|
||||||
use crate::de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
|
use crate::de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
|
||||||
|
use crate::private;
|
||||||
|
|
||||||
pub const FIELDS: &[&str] = &["start"];
|
pub const FIELDS: &[&str] = &["start"];
|
||||||
|
|
||||||
@@ -2665,7 +2667,7 @@ mod range_from {
|
|||||||
match value {
|
match value {
|
||||||
b"start" => Ok(Field::Start),
|
b"start" => Ok(Field::Start),
|
||||||
_ => {
|
_ => {
|
||||||
let value = crate::lib::from_utf8_lossy(value);
|
let value = private::string::from_utf8_lossy(value);
|
||||||
Err(Error::unknown_field(&*value, FIELDS))
|
Err(Error::unknown_field(&*value, FIELDS))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2761,6 +2763,7 @@ mod range_to {
|
|||||||
use crate::lib::*;
|
use crate::lib::*;
|
||||||
|
|
||||||
use crate::de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
|
use crate::de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
|
||||||
|
use crate::private;
|
||||||
|
|
||||||
pub const FIELDS: &[&str] = &["end"];
|
pub const FIELDS: &[&str] = &["end"];
|
||||||
|
|
||||||
@@ -2803,7 +2806,7 @@ mod range_to {
|
|||||||
match value {
|
match value {
|
||||||
b"end" => Ok(Field::End),
|
b"end" => Ok(Field::End),
|
||||||
_ => {
|
_ => {
|
||||||
let value = crate::lib::from_utf8_lossy(value);
|
let value = private::string::from_utf8_lossy(value);
|
||||||
Err(Error::unknown_field(&*value, FIELDS))
|
Err(Error::unknown_field(&*value, FIELDS))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,7 +103,6 @@ mod lib {
|
|||||||
pub use self::core::{cmp, mem};
|
pub use self::core::{cmp, mem};
|
||||||
|
|
||||||
pub use self::core::cell::{Cell, RefCell};
|
pub use self::core::cell::{Cell, RefCell};
|
||||||
|
|
||||||
pub use self::core::cmp::Reverse;
|
pub use self::core::cmp::Reverse;
|
||||||
pub use self::core::fmt::{self, Debug, Display, Write as FmtWrite};
|
pub use self::core::fmt::{self, Debug, Display, Write as FmtWrite};
|
||||||
pub use self::core::marker::PhantomData;
|
pub use self::core::marker::PhantomData;
|
||||||
@@ -203,27 +202,6 @@ mod lib {
|
|||||||
|
|
||||||
#[cfg(not(no_core_num_saturating))]
|
#[cfg(not(no_core_num_saturating))]
|
||||||
pub use self::core::num::Saturating;
|
pub use self::core::num::Saturating;
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub fn from_utf8_lossy(bytes: &[u8]) -> Cow<'_, str> {
|
|
||||||
String::from_utf8_lossy(bytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
// The generated code calls this like:
|
|
||||||
//
|
|
||||||
// let value = &_serde::__private::from_utf8_lossy(bytes);
|
|
||||||
// Err(_serde::de::Error::unknown_variant(value, VARIANTS))
|
|
||||||
//
|
|
||||||
// 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 = "alloc")))]
|
|
||||||
#[doc(hidden)]
|
|
||||||
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}")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// None of this crate's error handling needs the `From::from` error conversion
|
// None of this crate's error handling needs the `From::from` error conversion
|
||||||
@@ -259,14 +237,10 @@ pub use crate::de::{Deserialize, Deserializer};
|
|||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use crate::ser::{Serialize, Serializer};
|
pub use crate::ser::{Serialize, Serializer};
|
||||||
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub use lib::from_utf8_lossy;
|
|
||||||
|
|
||||||
// Used by generated code. Not public API.
|
// Used by generated code. Not public API.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[path = "private/mod.rs"]
|
#[path = "private/mod.rs"]
|
||||||
pub mod __private;
|
pub mod __private;
|
||||||
#[cfg(all(not(no_serde_derive), any(feature = "std", feature = "alloc")))]
|
|
||||||
use self::__private as private;
|
use self::__private as private;
|
||||||
|
|
||||||
#[path = "de/seed.rs"]
|
#[path = "de/seed.rs"]
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
#[cfg(all(not(no_serde_derive), any(feature = "std", feature = "alloc")))]
|
#[cfg(all(not(no_serde_derive), any(feature = "std", feature = "alloc")))]
|
||||||
mod content;
|
mod content;
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub mod string;
|
||||||
|
|
||||||
#[cfg(all(not(no_serde_derive), any(feature = "std", feature = "alloc")))]
|
#[cfg(all(not(no_serde_derive), any(feature = "std", feature = "alloc")))]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub use self::content::{Content, ContentVisitor};
|
pub use self::content::{Content, ContentVisitor};
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
use crate::lib::*;
|
||||||
|
|
||||||
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub fn from_utf8_lossy(bytes: &[u8]) -> Cow<'_, str> {
|
||||||
|
String::from_utf8_lossy(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The generated code calls this like:
|
||||||
|
//
|
||||||
|
// let value = &_serde::__private::from_utf8_lossy(bytes);
|
||||||
|
// Err(_serde::de::Error::unknown_variant(value, VARIANTS))
|
||||||
|
//
|
||||||
|
// 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 = "alloc")))]
|
||||||
|
#[doc(hidden)]
|
||||||
|
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}")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user