Skip to main content

CBox

Struct CBox 

Source
pub struct CBox<T, TAllocator: Allocator> { /* private fields */ }
Expand description

The ABI-stable box type. This type is equivalent to the standard Box type, except it is suitable for FFI and also accepts any allocator.

Implementations§

Source§

impl<T, TAllocator: Allocator> CBox<T, TAllocator>

Source

pub fn new(value: T) -> Result<Self, CBoxError>
where TAllocator: Default,

Creates a new CBox with the default allocator.

§Errors

For details see CBoxError.

Source

pub fn with_allocator( value: T, allocator: TAllocator, ) -> Result<Self, CBoxError>

Creates a new CBox with a custom allocator.

§Errors

For details see CBoxError.

Source

pub const fn data(box_: &Self) -> &T

Returns a reference to the data stored in the CBox.

Source

pub const fn data_mut(box_: &mut Self) -> &mut T

Returns a mutable reference to the data stored in the CBox.

Source

pub const fn data_ptr(box_: &Self) -> *const T

Returns a raw pointer to the underlying data stored in the CBox.

The caller must ensure that the pointer does not outlive the CBox.

Source

pub const fn into_raw_ptr(box_: Self) -> *mut u8

Converts the CBox into a raw pointer.

§Notes
  • This method does not touch internal structure of the CBox, self is simply forgotten.
  • The caller must ensure that the pointer does not outlive the CBox.
Source

pub const unsafe fn from_raw_ptr(ptr: *mut u8) -> Self

Converts a raw pointer back to a CBox container.

§Safety
  • The caller must ensure that the pointer came from the previous call to CBox::into_raw_ptr.
  • The caller must ensure that the raw pointer won’t be used after the call.

Otherwise the behavior is undefined.

Source

pub const fn data_ptr_mut(box_: &mut Self) -> *mut T

Returns a raw mutable pointer to the underlying data stored in the CBox.

The caller must ensure that the pointer does not outlive the CBox.

Source

pub fn unpack(box_: Self) -> T

Unpacks the CBox and returns the data. The underlying memory gets deallocated.

Trait Implementations§

Source§

impl<T, TAllocator: Allocator> AsMut<T> for CBox<T, TAllocator>

Source§

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

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

impl<T, TAllocator: Allocator> AsRef<T> for CBox<T, TAllocator>

Source§

fn as_ref(&self) -> &T

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

impl<T, TAllocator: Allocator> Borrow<T> for CBox<T, TAllocator>

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T, TAllocator: Allocator> BorrowMut<T> for CBox<T, TAllocator>

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T, TAllocator> Clone for CBox<T, TAllocator>
where T: TryClone, TAllocator: Allocator + TryClone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug, TAllocator: Debug + Allocator> Debug for CBox<T, TAllocator>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, TAllocator: Allocator> Deref for CBox<T, TAllocator>

Source§

type Target = T

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<T, TAllocator: Allocator> DerefMut for CBox<T, TAllocator>

Source§

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

Mutably dereferences the value.
Source§

impl<'de, T, TAllocator: Allocator + Default> Deserialize<'de> for CBox<T, TAllocator>
where T: Deserialize<'de>,

Available on crate feature serde only.
Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T, TAllocator: Allocator> Drop for CBox<T, TAllocator>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<T: ReprC, TAllocator: Allocator> ReprC for CBox<T, TAllocator>

Source§

const CHECK: ()

This field is used for const checks only.
Source§

impl<T, TAllocator: Allocator> Serialize for CBox<T, TAllocator>
where T: Serialize,

Available on crate feature serde only.
Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T, TAllocator> TryClone for CBox<T, TAllocator>
where T: TryClone, TAllocator: Allocator + TryClone,

Source§

type Error = CBoxTryCloneError

Source§

fn try_clone(&self) -> Result<Self, Self::Error>

Tries to clone the type. Read more

Auto Trait Implementations§

§

impl<T, TAllocator> !Send for CBox<T, TAllocator>

§

impl<T, TAllocator> !Sync for CBox<T, TAllocator>

§

impl<T, TAllocator> Freeze for CBox<T, TAllocator>

§

impl<T, TAllocator> RefUnwindSafe for CBox<T, TAllocator>
where T: RefUnwindSafe, TAllocator: RefUnwindSafe,

§

impl<T, TAllocator> Unpin for CBox<T, TAllocator>
where T: Unpin, TAllocator: Unpin,

§

impl<T, TAllocator> UnsafeUnpin for CBox<T, TAllocator>

§

impl<T, TAllocator> UnwindSafe for CBox<T, TAllocator>
where T: UnwindSafe, TAllocator: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.