Created
March 10, 2015 16:48
-
-
Save jviereck/129b0f5fc32d99894cd9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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