mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-26 06:17:55 +00:00
Make size_hint private
This commit is contained in:
@@ -8,7 +8,7 @@ use crate::private;
|
||||
use crate::seed::InPlaceSeed;
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
use crate::de::size_hint;
|
||||
use crate::private::size_hint;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@@ -120,7 +120,6 @@ pub mod value;
|
||||
|
||||
mod ignored_any;
|
||||
mod impls;
|
||||
pub mod size_hint;
|
||||
|
||||
pub use self::ignored_any::IgnoredAny;
|
||||
pub use crate::seed::InPlaceSeed;
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
//! 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,
|
||||
{
|
||||
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;
|
||||
|
||||
if mem::size_of::<Element>() == 0 {
|
||||
0
|
||||
} else {
|
||||
cmp::min(
|
||||
hint.unwrap_or(0),
|
||||
MAX_PREALLOC_BYTES / mem::size_of::<Element>(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn helper(bounds: (usize, Option<usize>)) -> Option<usize> {
|
||||
match bounds {
|
||||
(lower, Some(upper)) if lower == upper => Some(upper),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user