pub struct FuriBox<T: ?Sized>(/* private fields */);Expand description
Heap-allocated value.
This is intended for situations where it is not possible to rely upon a global allocator.
Most users should make use of flipperzero-alloc.
Implementations§
Source§impl<T> FuriBox<T>
impl<T> FuriBox<T>
Sourcepub fn new(value: T) -> Self
pub fn new(value: T) -> Self
Allocates and initializes a correctly aligned value on the system heap.
Sourcepub fn into_raw(b: FuriBox<T>) -> *mut T
pub fn into_raw(b: FuriBox<T>) -> *mut T
Consume the box and return raw pointer.
Caller is responsible for calling T::drop() and freeing the pointer with aligned_free.
Sourcepub unsafe fn from_raw(raw: *mut T) -> Self
pub unsafe fn from_raw(raw: *mut T) -> Self
Constructs a box from a raw pointer.
§Safety
This function is unsafe because improper use may lead to memory problems.
The caller is responsible for ensuring the pointer is non-null, was allocated using aligned_malloc
with the correct alignment for T and that the memory represents a valid T.
Sourcepub fn as_ptr(b: &FuriBox<T>) -> *const T
pub fn as_ptr(b: &FuriBox<T>) -> *const T
Returns a raw pointer to the Box’s contents.
The caller must ensure that the Box outlives the pointer this function returns, or else it will end up dangling.
The caller must also ensure that the memory the pointer (non-transitively) points to
is never written to (except inside an UnsafeCell) using this pointer
or any pointer derived from it. If you need to mutate the contents of the Box, use `as_mut_ptr``.
This method guarantees that for the purpose of the aliasing model, this method does not materialize a reference to the underlying memory, and thus the returned pointer will remain valid when mixed with other calls to as_ptr and as_mut_ptr.
Sourcepub fn as_mut_ptr(b: &mut FuriBox<T>) -> *mut T
pub fn as_mut_ptr(b: &mut FuriBox<T>) -> *mut T
Returns a raw mutable pointer to the Box’s contents.
The caller must ensure that the Box outlives the pointer this function returns, or else it will end up dangling.
This method guarantees that for the purpose of the aliasing model,
this method does not materialize a reference to the underlying memory,
and thus the returned pointer will remain valid when mixed with
other calls to as_ptr`` and as_mut_ptr``.