Skip to content

Instantly share code, notes, and snippets.

@jviereck
Created March 10, 2015 16:48
Show Gist options
  • Select an option

  • Save jviereck/129b0f5fc32d99894cd9 to your computer and use it in GitHub Desktop.

Select an option

Save jviereck/129b0f5fc32d99894cd9 to your computer and use it in GitHub Desktop.
pub struct RefList<T: 'local> {
// Use this arena to create the node elements in the list.
node_arena: TypedArena<T>
// Store the last object allocated from the `node_arean` in this field.
list_tail: Option<&'local mut T>,
}
impl<T> RefList<T: 'local> {
fn new(capacity: usize) -> RefList<T> {
RefList {
list_tail: None,
node_arena: TypedArena::with_capacity(capacity)
}
}
fn push_back(&mut self, new_tail: T) {
// Allocate the new value `new_tail` inside of the arena and store
// the recieved object from the arena on the `list_tail`.
self.list_tail = Some(self.node_arena.alloc(T));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment