1use crate::{Arbitrary, any, any_where};
4
5pub fn any_vec<T, const MAX_LENGTH: usize>() -> Vec<T>
7where
8 T: Arbitrary,
9{
10 let real_length: usize = any_where(|sz| *sz <= MAX_LENGTH);
11 match real_length {
12 0 => vec![],
13 exact if exact == MAX_LENGTH => exact_vec::<T, MAX_LENGTH>(),
14 _ => {
15 let mut any_vec = exact_vec::<T, MAX_LENGTH>();
16 any_vec.truncate(real_length);
17 any_vec.shrink_to_fit();
18 assert!(any_vec.capacity() == any_vec.len());
19 any_vec
20 }
21 }
22}
23
24pub fn exact_vec<T, const EXACT_LENGTH: usize>() -> Vec<T>
26where
27 T: Arbitrary,
28{
29 let boxed_array: Box<[T; EXACT_LENGTH]> = Box::new(any());
30 <[T]>::into_vec(boxed_array)
31}