1 | use crate::lib::*; |
2 | |
3 | pub fn from_bounds<I>(iter: &I) -> Option<usize> |
4 | where |
5 | I: Iterator, |
6 | { |
7 | helper(bounds:iter.size_hint()) |
8 | } |
9 | |
10 | #[cfg (any(feature = "std" , feature = "alloc" ))] |
11 | 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 | v1:hint.unwrap_or(0), |
19 | MAX_PREALLOC_BYTES / mem::size_of::<Element>(), |
20 | ) |
21 | } |
22 | } |
23 | |
24 | fn helper(bounds: (usize, Option<usize>)) -> Option<usize> { |
25 | match bounds { |
26 | (lower: usize, Some(upper: usize)) if lower == upper => Some(upper), |
27 | _ => None, |
28 | } |
29 | } |
30 | |