Make size_hint private

This commit is contained in:
David Tolnay
2025-09-13 12:12:05 -07:00
parent 7f831225a9
commit f916ec6baa
7 changed files with 11 additions and 12 deletions
+1 -1
View File
@@ -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;
////////////////////////////////////////////////////////////////////////////////
-1
View File
@@ -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;
-33
View File
@@ -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,
}
}
+2 -1
View File
@@ -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;
////////////////////////////////////////////////////////////////////////////////