1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 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, } }