Closed Qwertycrackers closed 5 years ago
@Qwertycrackers would collecting an iterator into the arena allocated slice work for you?
@maciejhirsz Yeah, that would be good. If you think it's a good idea I can write a draft implementation and submit a PR.
Sure, would love a PR. Basically the same signature you have proposed, but use Iterator
instead of Fn
closure. size
is still necessary since we need to make sure there is enough room left in the current page, but it's cool if the iterator is shorter than the size
(it's basically max capacity).
Thanks for the PR, this is now released on crates.
I want to use this crate, but I can't seem to quite make the API fit my use case. I'm pulling an an unpredictable number of items into my program through I/O, and I want to place them in an arena. I can query how many items there will be, so the size of the array must be dynamic, but it will not be resized after this.
The arena has an
allocate_from_slice
function, but this requires that I already have a slice to copy onto the heap. I really want to initialize my objects directly into the arena.My thinking is that this problem could be addressed with some "functional style" allocation methods on the
Arena
; something likealloc_from_closure<T: Copy,F: Fn(index: usize) -> T>(size: usize, source: &F) -> &'arena [T]
. Similar methods could allow initialization with an interator, or aFnMut
. I would be perfectly to build this functionality myself and upstream it if desired.