mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-29 16:27:55 +00:00
Make size_hint private
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user