mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-22 06:48:00 +00:00
Merge pull request #2969 from dtolnay/coreprivate
Reduce visibility of serde_core implementation details
This commit is contained in:
@@ -16,7 +16,7 @@ pub use self::content::{
|
||||
TagOrContentField, TagOrContentFieldVisitor, TaggedContentVisitor, UntaggedUnitVisitor,
|
||||
};
|
||||
|
||||
pub use serde_core::de::InPlaceSeed;
|
||||
pub use serde_core::__private::InPlaceSeed;
|
||||
|
||||
/// If the missing field is of type `Option<T>` then treat is as `None`,
|
||||
/// otherwise it is an error.
|
||||
@@ -209,11 +209,11 @@ mod content {
|
||||
use crate::lib::*;
|
||||
|
||||
use crate::de::{
|
||||
self, size_hint, Deserialize, DeserializeSeed, Deserializer, EnumAccess, Expected,
|
||||
IgnoredAny, MapAccess, SeqAccess, Unexpected, Visitor,
|
||||
self, Deserialize, DeserializeSeed, Deserializer, EnumAccess, Expected, IgnoredAny,
|
||||
MapAccess, SeqAccess, Unexpected, Visitor,
|
||||
};
|
||||
pub use serde_core::__private::Content;
|
||||
use serde_core::__private::ContentVisitor;
|
||||
use serde_core::__private::{size_hint, ContentVisitor};
|
||||
|
||||
pub fn content_as_str<'a, 'de>(content: &'a Content<'de>) -> Option<&'a str> {
|
||||
match *content {
|
||||
|
||||
@@ -15,11 +15,7 @@ pub use crate::lib::option::Option::{self, None, Some};
|
||||
pub use crate::lib::ptr;
|
||||
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"))]
|
||||
pub use crate::lib::{ToString, Vec};
|
||||
|
||||
mod string {
|
||||
pub use serde_core::from_utf8_lossy;
|
||||
}
|
||||
|
||||
@@ -4,11 +4,10 @@ use crate::de::{
|
||||
Deserialize, Deserializer, EnumAccess, Error, MapAccess, SeqAccess, Unexpected, VariantAccess,
|
||||
Visitor,
|
||||
};
|
||||
|
||||
use crate::seed::InPlaceSeed;
|
||||
use crate::private::{self, InPlaceSeed};
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
use crate::de::size_hint;
|
||||
use crate::private::size_hint;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -2174,7 +2173,7 @@ impl<'de> Deserialize<'de> for Duration {
|
||||
b"secs" => Ok(Field::Secs),
|
||||
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))
|
||||
}
|
||||
}
|
||||
@@ -2465,6 +2464,7 @@ mod range {
|
||||
use crate::lib::*;
|
||||
|
||||
use crate::de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
|
||||
use crate::private;
|
||||
|
||||
pub const FIELDS: &[&str] = &["start", "end"];
|
||||
|
||||
@@ -2510,7 +2510,7 @@ mod range {
|
||||
b"start" => Ok(Field::Start),
|
||||
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))
|
||||
}
|
||||
}
|
||||
@@ -2623,6 +2623,7 @@ mod range_from {
|
||||
use crate::lib::*;
|
||||
|
||||
use crate::de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
|
||||
use crate::private;
|
||||
|
||||
pub const FIELDS: &[&str] = &["start"];
|
||||
|
||||
@@ -2665,7 +2666,7 @@ mod range_from {
|
||||
match value {
|
||||
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))
|
||||
}
|
||||
}
|
||||
@@ -2761,6 +2762,7 @@ mod range_to {
|
||||
use crate::lib::*;
|
||||
|
||||
use crate::de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
|
||||
use crate::private;
|
||||
|
||||
pub const FIELDS: &[&str] = &["end"];
|
||||
|
||||
@@ -2803,7 +2805,7 @@ mod range_to {
|
||||
match value {
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,10 +120,9 @@ pub mod value;
|
||||
|
||||
mod ignored_any;
|
||||
mod impls;
|
||||
pub mod size_hint;
|
||||
|
||||
pub use self::ignored_any::IgnoredAny;
|
||||
pub use crate::seed::InPlaceSeed;
|
||||
pub use crate::private::InPlaceSeed;
|
||||
#[cfg(all(not(feature = "std"), no_core_error))]
|
||||
#[doc(no_inline)]
|
||||
pub use crate::std_error::Error as StdError;
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
use crate::lib::*;
|
||||
|
||||
use self::private::{First, Second};
|
||||
use crate::de::{self, size_hint, Deserializer, Expected, IntoDeserializer, SeqAccess, Visitor};
|
||||
use crate::de::{self, Deserializer, Expected, IntoDeserializer, SeqAccess, Visitor};
|
||||
use crate::private::size_hint;
|
||||
use crate::ser;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
+1
-33
@@ -103,7 +103,6 @@ mod lib {
|
||||
pub use self::core::{cmp, mem};
|
||||
|
||||
pub use self::core::cell::{Cell, RefCell};
|
||||
|
||||
pub use self::core::cmp::Reverse;
|
||||
pub use self::core::fmt::{self, Debug, Display, Write as FmtWrite};
|
||||
pub use self::core::marker::PhantomData;
|
||||
@@ -203,27 +202,6 @@ mod lib {
|
||||
|
||||
#[cfg(not(no_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
|
||||
@@ -243,8 +221,6 @@ macro_rules! tri {
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
#[doc(hidden)]
|
||||
pub use crate::lib::result::Result;
|
||||
|
||||
#[macro_use]
|
||||
mod integer128;
|
||||
@@ -259,20 +235,12 @@ pub use crate::de::{Deserialize, Deserializer};
|
||||
#[doc(inline)]
|
||||
pub use crate::ser::{Serialize, Serializer};
|
||||
|
||||
#[doc(hidden)]
|
||||
pub use lib::from_utf8_lossy;
|
||||
|
||||
// Used by generated code. Not public API.
|
||||
#[cfg(all(not(no_serde_derive), any(feature = "std", feature = "alloc")))]
|
||||
#[doc(hidden)]
|
||||
#[path = "private.rs"]
|
||||
#[path = "private/mod.rs"]
|
||||
pub mod __private;
|
||||
#[cfg(all(not(no_serde_derive), any(feature = "std", feature = "alloc")))]
|
||||
use self::__private as private;
|
||||
|
||||
#[path = "de/seed.rs"]
|
||||
mod seed;
|
||||
|
||||
#[cfg(all(not(feature = "std"), no_core_error))]
|
||||
mod std_error;
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ macro_rules! forward_to_deserialize_any {
|
||||
macro_rules! forward_to_deserialize_any_method {
|
||||
($func:ident<$l:tt, $v:ident>($($arg:ident : $ty:ty),*)) => {
|
||||
#[inline]
|
||||
fn $func<$v>(self, $($arg: $ty,)* visitor: $v) -> $crate::Result<$v::Value, <Self as $crate::de::Deserializer<$l>>::Error>
|
||||
fn $func<$v>(self, $($arg: $ty,)* visitor: $v) -> $crate::__private::Result<$v::Value, <Self as $crate::de::Deserializer<$l>>::Error>
|
||||
where
|
||||
$v: $crate::de::Visitor<$l>,
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use crate::de::{
|
||||
self, size_hint, Deserialize, Deserializer, EnumAccess, MapAccess, SeqAccess, Visitor,
|
||||
};
|
||||
use crate::de::{self, Deserialize, Deserializer, EnumAccess, MapAccess, SeqAccess, Visitor};
|
||||
use crate::lib::*;
|
||||
use crate::private::size_hint;
|
||||
|
||||
// Used from generated code to buffer the contents of the Deserializer when
|
||||
// deserializing untagged enums and internally tagged enums.
|
||||
@@ -0,0 +1,17 @@
|
||||
#[cfg(all(not(no_serde_derive), any(feature = "std", feature = "alloc")))]
|
||||
mod content;
|
||||
mod seed;
|
||||
|
||||
#[doc(hidden)]
|
||||
pub mod size_hint;
|
||||
|
||||
#[doc(hidden)]
|
||||
pub mod string;
|
||||
|
||||
#[cfg(all(not(no_serde_derive), any(feature = "std", feature = "alloc")))]
|
||||
#[doc(hidden)]
|
||||
pub use self::content::{Content, ContentVisitor};
|
||||
#[doc(hidden)]
|
||||
pub use self::seed::InPlaceSeed;
|
||||
#[doc(hidden)]
|
||||
pub use crate::lib::result::Result;
|
||||
@@ -1,8 +1,6 @@
|
||||
//! Provides helpers for creating size hints for container deserialization.
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
use crate::lib::*;
|
||||
|
||||
/// Extracts the exact size of an iterator if it has a known upper bound and it matches the lower bound.
|
||||
pub fn from_bounds<I>(iter: &I) -> Option<usize>
|
||||
where
|
||||
I: Iterator,
|
||||
@@ -10,7 +8,6 @@ where
|
||||
helper(iter.size_hint())
|
||||
}
|
||||
|
||||
/// Returns conservative size estimate for a container, clamping the result to a maximum size.
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
pub fn cautious<Element>(hint: Option<usize>) -> usize {
|
||||
const MAX_PREALLOC_BYTES: usize = 1024 * 1024;
|
||||
@@ -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