Efficiency of flattening and collecting slices
问题 If one uses the standard .flatten().collect::<Box<[T]>>() on an Iterator<Item=&[T]> where T: Copy , does it: perform a single allocation; and use memcpy to copy each item to the destination or does it do something less efficient? 回答1: Box<[T]> does not implement FromIterator<&T> , so I'll assume your actual inner iterator is something that yields owned T s. FromIterator<T> for Box<[T]> forwards to Vec<T> , which uses size_hint() to reserve space for lower + 1 items, and reallocates as it