FuriBox

Struct FuriBox 

Source
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>

Source

pub fn new(value: T) -> Self

Allocates and initializes a correctly aligned value on the system heap.

Source

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.

Source

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.

Source

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.

Source

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``.

Trait Implementations§

Source§

impl<T: ?Sized> AsMut<T> for FuriBox<T>

Source§

fn as_mut(&mut self) -> &mut T

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T: ?Sized> AsRef<T> for FuriBox<T>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: ?Sized> Deref for FuriBox<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T: ?Sized> DerefMut for FuriBox<T>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T: ?Sized> Drop for FuriBox<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: PartialEq + ?Sized> PartialEq for FuriBox<T>

Source§

fn eq(&self, other: &FuriBox<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Eq + ?Sized> Eq for FuriBox<T>

Source§

impl<T: ?Sized> StructuralPartialEq for FuriBox<T>

Auto Trait Implementations§

§

impl<T> Freeze for FuriBox<T>
where T: ?Sized,

§

impl<T> RefUnwindSafe for FuriBox<T>
where T: RefUnwindSafe + ?Sized,

§

impl<T> !Send for FuriBox<T>

§

impl<T> !Sync for FuriBox<T>

§

impl<T> Unpin for FuriBox<T>
where T: ?Sized,

§

impl<T> UnwindSafe for FuriBox<T>
where T: RefUnwindSafe + ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.