Move size_hint module out of private::de

This commit is contained in:
David Tolnay 2021-01-24 20:21:57 -08:00
parent 1c03647656
commit 38edb473de
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
5 changed files with 24 additions and 26 deletions

View File

@ -10,7 +10,7 @@ use de::MapAccess;
use seed::InPlaceSeed;
#[cfg(any(feature = "std", feature = "alloc"))]
use __private::de::size_hint;
use __private::size_hint;
////////////////////////////////////////////////////////////////////////////////

View File

@ -24,7 +24,7 @@
use lib::*;
use self::private::{First, Second};
use __private::de::size_hint;
use __private::size_hint;
use de::{self, Deserializer, Expected, IntoDeserializer, SeqAccess, Visitor};
use ser;

View File

@ -191,29 +191,6 @@ where
.map(From::from)
}
pub mod size_hint {
use lib::*;
pub fn from_bounds<I>(iter: &I) -> Option<usize>
where
I: Iterator,
{
helper(iter.size_hint())
}
#[inline]
pub fn cautious(hint: Option<usize>) -> usize {
cmp::min(hint.unwrap_or(0), 4096)
}
fn helper(bounds: (usize, Option<usize>)) -> Option<usize> {
match bounds {
(lower, Some(upper)) if lower == upper => Some(upper),
_ => None,
}
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
mod content {
// This module is private and nothing here should be used outside of
@ -228,7 +205,7 @@ mod content {
use lib::*;
use super::size_hint;
use __private::size_hint;
use de::{
self, Deserialize, DeserializeSeed, Deserializer, EnumAccess, Expected, IgnoredAny,
MapAccess, SeqAccess, Unexpected, Visitor,

View File

@ -1,5 +1,6 @@
pub mod de;
pub mod ser;
pub mod size_hint;
// FIXME: #[cfg(doctest)] once https://github.com/rust-lang/rust/issues/67295 is fixed.
pub mod doc;

View File

@ -0,0 +1,20 @@
use lib::*;
pub fn from_bounds<I>(iter: &I) -> Option<usize>
where
I: Iterator,
{
helper(iter.size_hint())
}
#[inline]
pub fn cautious(hint: Option<usize>) -> usize {
cmp::min(hint.unwrap_or(0), 4096)
}
fn helper(bounds: (usize, Option<usize>)) -> Option<usize> {
match bounds {
(lower, Some(upper)) if lower == upper => Some(upper),
_ => None,
}
}