fitzgen / bumpalo

A fast bump allocation arena for Rust
https://docs.rs/bumpalo
Apache License 2.0
1.42k stars 112 forks source link

Implement the necessary traits for collections #102

Closed pickfire closed 3 years ago

pickfire commented 3 years ago
error[E0277]: a value of type `bumpalo::collections::Vec<'_, (&[u8], u64)>` cannot be built from an iterator over elements of type `(&[u8], u64)`
  --> main.rs:73:61
   |
73 |     let mut ordered: Vec<(&[u8], u64)> = counts.into_iter().collect();
   |                                                             ^^^^^^^ value of type `bumpalo::collections::Vec<'_, (&[u8], u64)>` cannot be built from `std::iter::Iterator<Item=(&[u8], u64)>`
   |
   = help: the trait `FromIterator<(&[u8], u64)>` is not implemented for `bumpalo::collections::Vec<'_, (&[u8], u64)>`

counts have type HashMap<&'bump [u8], u64>

Can we implement FromIter and other trait to support collect for feature parity with standard library?

fitzgen commented 3 years ago

It won't work because you need a reference to the Bump to collect them into.

Extend is implemented, however, and side steps this problem since an already-constructed bumpalo::collections::Vec has a reference to the Bump internally.

pickfire commented 3 years ago

I tried using Bump.alloc_slice_copy and that works nicely, I saw that on another place.