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
+2 -3
View File
@@ -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.
+3
View File
@@ -1,6 +1,9 @@
#[cfg(all(not(no_serde_derive), any(feature = "std", feature = "alloc")))]
mod content;
#[doc(hidden)]
pub mod size_hint;
#[doc(hidden)]
pub mod string;
+30
View File
@@ -0,0 +1,30 @@
#[cfg(any(feature = "std", feature = "alloc"))]
use crate::lib::*;
pub fn from_bounds<I>(iter: &I) -> Option<usize>
where
I: Iterator,
{
helper(iter.size_hint())
}
#[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,
}
}