1 use crate::lib::*;
2
from_bounds<I>(iter: &I) -> Option<usize> where I: Iterator,3 pub fn from_bounds<I>(iter: &I) -> Option<usize>
4 where
5 I: Iterator,
6 {
7 helper(iter.size_hint())
8 }
9
10 #[cfg(any(feature = "std", feature = "alloc"))]
cautious<Element>(hint: Option<usize>) -> usize11 pub fn cautious<Element>(hint: Option<usize>) -> usize {
12 const MAX_PREALLOC_BYTES: usize = 1024 * 1024;
13
14 if mem::size_of::<Element>() == 0 {
15 0
16 } else {
17 cmp::min(
18 hint.unwrap_or(0),
19 MAX_PREALLOC_BYTES / mem::size_of::<Element>(),
20 )
21 }
22 }
23
helper(bounds: (usize, Option<usize>)) -> Option<usize>24 fn helper(bounds: (usize, Option<usize>)) -> Option<usize> {
25 match bounds {
26 (lower, Some(upper)) if lower == upper => Some(upper),
27 _ => None,
28 }
29 }
30