use crate::lib::*; pub fn from_bounds(iter: &I) -> Option where I: Iterator, { helper(iter.size_hint()) } #[cfg(any(feature = "std", feature = "alloc"))] pub fn cautious(hint: Option) -> usize { const MAX_PREALLOC_BYTES: usize = 1024 * 1024; if mem::size_of::() == 0 { 0 } else { cmp::min( hint.unwrap_or(0), MAX_PREALLOC_BYTES / mem::size_of::(), ) } } fn helper(bounds: (usize, Option)) -> Option { match bounds { (lower, Some(upper)) if lower == upper => Some(upper), _ => None, } }