mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-13 07:51:03 +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,
|
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`,
|
/// If the missing field is of type `Option<T>` then treat is as `None`,
|
||||||
/// otherwise it is an error.
|
/// otherwise it is an error.
|
||||||
@@ -209,11 +209,11 @@ mod content {
|
|||||||
use crate::lib::*;
|
use crate::lib::*;
|
||||||
|
|
||||||
use crate::de::{
|
use crate::de::{
|
||||||
self, size_hint, Deserialize, DeserializeSeed, Deserializer, EnumAccess, Expected,
|
self, Deserialize, DeserializeSeed, Deserializer, EnumAccess, Expected, IgnoredAny,
|
||||||
IgnoredAny, MapAccess, SeqAccess, Unexpected, Visitor,
|
MapAccess, SeqAccess, Unexpected, Visitor,
|
||||||
};
|
};
|
||||||
pub use serde_core::__private::Content;
|
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> {
|
pub fn content_as_str<'a, 'de>(content: &'a Content<'de>) -> Option<&'a str> {
|
||||||
match *content {
|
match *content {
|
||||||
|
|||||||
@@ -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,11 +4,10 @@ use crate::de::{
|
|||||||
Deserialize, Deserializer, EnumAccess, Error, MapAccess, SeqAccess, Unexpected, VariantAccess,
|
Deserialize, Deserializer, EnumAccess, Error, MapAccess, SeqAccess, Unexpected, VariantAccess,
|
||||||
Visitor,
|
Visitor,
|
||||||
};
|
};
|
||||||
|
use crate::private::{self, InPlaceSeed};
|
||||||
use crate::seed::InPlaceSeed;
|
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[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"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 +2464,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 +2510,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 +2623,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 +2666,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 +2762,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 +2805,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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,10 +120,9 @@ pub mod value;
|
|||||||
|
|
||||||
mod ignored_any;
|
mod ignored_any;
|
||||||
mod impls;
|
mod impls;
|
||||||
pub mod size_hint;
|
|
||||||
|
|
||||||
pub use self::ignored_any::IgnoredAny;
|
pub use self::ignored_any::IgnoredAny;
|
||||||
pub use crate::seed::InPlaceSeed;
|
pub use crate::private::InPlaceSeed;
|
||||||
#[cfg(all(not(feature = "std"), no_core_error))]
|
#[cfg(all(not(feature = "std"), no_core_error))]
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use crate::std_error::Error as StdError;
|
pub use crate::std_error::Error as StdError;
|
||||||
|
|||||||
@@ -24,7 +24,8 @@
|
|||||||
use crate::lib::*;
|
use crate::lib::*;
|
||||||
|
|
||||||
use self::private::{First, Second};
|
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;
|
use crate::ser;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
+1
-33
@@ -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
|
||||||
@@ -243,8 +221,6 @@ macro_rules! tri {
|
|||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod macros;
|
mod macros;
|
||||||
#[doc(hidden)]
|
|
||||||
pub use crate::lib::result::Result;
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod integer128;
|
mod integer128;
|
||||||
@@ -259,20 +235,12 @@ 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.
|
||||||
#[cfg(all(not(no_serde_derive), any(feature = "std", feature = "alloc")))]
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[path = "private.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"]
|
|
||||||
mod seed;
|
|
||||||
|
|
||||||
#[cfg(all(not(feature = "std"), no_core_error))]
|
#[cfg(all(not(feature = "std"), no_core_error))]
|
||||||
mod std_error;
|
mod std_error;
|
||||||
|
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ macro_rules! forward_to_deserialize_any {
|
|||||||
macro_rules! forward_to_deserialize_any_method {
|
macro_rules! forward_to_deserialize_any_method {
|
||||||
($func:ident<$l:tt, $v:ident>($($arg:ident : $ty:ty),*)) => {
|
($func:ident<$l:tt, $v:ident>($($arg:ident : $ty:ty),*)) => {
|
||||||
#[inline]
|
#[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
|
where
|
||||||
$v: $crate::de::Visitor<$l>,
|
$v: $crate::de::Visitor<$l>,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
use crate::de::{
|
use crate::de::{self, Deserialize, Deserializer, EnumAccess, MapAccess, SeqAccess, Visitor};
|
||||||
self, size_hint, Deserialize, Deserializer, EnumAccess, MapAccess, SeqAccess, Visitor,
|
|
||||||
};
|
|
||||||
use crate::lib::*;
|
use crate::lib::*;
|
||||||
|
use crate::private::size_hint;
|
||||||
|
|
||||||
// Used from generated code to buffer the contents of the Deserializer when
|
// Used from generated code to buffer the contents of the Deserializer when
|
||||||
// deserializing untagged enums and internally tagged enums.
|
// 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"))]
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
use crate::lib::*;
|
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>
|
pub fn from_bounds<I>(iter: &I) -> Option<usize>
|
||||||
where
|
where
|
||||||
I: Iterator,
|
I: Iterator,
|
||||||
@@ -10,7 +8,6 @@ where
|
|||||||
helper(iter.size_hint())
|
helper(iter.size_hint())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns conservative size estimate for a container, clamping the result to a maximum size.
|
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
pub fn cautious<Element>(hint: Option<usize>) -> usize {
|
pub fn cautious<Element>(hint: Option<usize>) -> usize {
|
||||||
const MAX_PREALLOC_BYTES: usize = 1024 * 1024;
|
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