> This is a pretty simple type, which is a vector that you can push into, but cannot modify the elements of. The data structure never moves an element once allocated, so you can push to the vec even while holding references to elements that have already been pushed.
This is the left-pad of rust. Reconsider your life decisions if you need to pull in an external dependency replicable with 30 lines of code:
use std::vec::Vec;
#[derive(Debug)]
pub struct AppendOnlyVec<T> {
inner: Vec<T>,
}
impl<T> AppendOnlyVec<T> {
pub fn new() -> Self {
Self {
inner: vec![],
}
}
pub fn push(&mut self, element: T) {
self.inner.push(element);
}
pub fn clear(&mut self) {
self.inner.clear();
}
}