diff options
Diffstat (limited to '')
-rw-r--r-- | vendor/serde/src/private/size_hint.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/vendor/serde/src/private/size_hint.rs b/vendor/serde/src/private/size_hint.rs new file mode 100644 index 000000000..ca71e616b --- /dev/null +++ b/vendor/serde/src/private/size_hint.rs @@ -0,0 +1,21 @@ +use lib::*; + +pub fn from_bounds<I>(iter: &I) -> Option<usize> +where + I: Iterator, +{ + helper(iter.size_hint()) +} + +#[cfg(any(feature = "std", feature = "alloc"))] +#[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, + } +} |