Crate stack_frame_allocators

Source
Expand description

A set of Allocators based on the concept of a stack and enforcing memory safety via scopes. These allocators use frames, where values can be pushed onto the frames. The allocators can only pop whole frames and all of its associated values.

Modules§

stack_frame_allocator
The StackFrameAllocator allows the creation of “Frames” where values can be pushed onto this frame. Frames only exist in the scope they’re created in using the new_frame function. At the end of a frame’s scope, the entire frame is popped, and the StackFrameAllocator will continue pushing items onto the previous frame. Because only one StackRef can exist at a time for a given value, both [get] and [get_mut] functions are safe, due to being able to be validated by the borrow checker at compile time.
stack_frame_dict_allocator
The StackFrameDictAllocator allows the creation of “Frames” where key value pairs can be pushed onto this frame. Frames only exist in the scope they’re created in using the new_frame function. At the end of a frame’s scope, the entire frame is popped, and the StackFrameDictAllocator will continue pushing items onto the previous frame. Key Value pairs can be grabbed by searching for the last entry with that key.
stack_ref
General Wrapper for References within either of the crate’s Stack Allocators: the StackFrameDictAllocator, and the StackFrameAllocator. Grabbing values from a StackFrameDictAllocator gives you unsafe_ref::StackRef’s because mutltiple StackRefs can be obtained which all point to the same value, thus you could make multiple mutable references to the same value which violates the rules of the borrow checker. Grabbing values from a StackFrameAllocator gives you safe_ref::StackRef’s because only one StackRef can point to a value at any given time, which means the borrow checker can validate that borrowing rules are being followed. There is also a static guarantee that the lifetime of a StackRef is the same lifetime of the Frame of the Value the StackRef is pointing to.