diff options
Diffstat (limited to 'third_party/rust/serde/src/private/size_hint.rs')
-rw-r--r-- | third_party/rust/serde/src/private/size_hint.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/third_party/rust/serde/src/private/size_hint.rs b/third_party/rust/serde/src/private/size_hint.rs new file mode 100644 index 0000000000..ca71e616bb --- /dev/null +++ b/third_party/rust/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, + } +} |