Skip to main content

Flat

Struct Flat 

Source
pub struct Flat<T: ?Sized, B: Buffer> { /* private fields */ }
Expand description

Inline-only storage for ?Sized types.

Stores a trait object (or slice) directly in a buffer of type B. The total struct size equals size_of::<B>().

  • Sized T: full buffer capacity, value at offset 0.
  • ?Sized T: one pointer-sized word reserved for metadata, value follows.

Use the flat! macro for ?Sized construction, or Flat::new for Sized types.

§Compile-time safety

The ?Sized metadata overhead (one pointer-sized word) is validated at compile time for hand-implemented Buffer types. All predefined buffers (B16+) satisfy this constraint.

Implementations§

Source§

impl<T: ?Sized, B: Buffer> Flat<T, B>

Source

pub const fn capacity() -> usize

Returns the usable value capacity in bytes.

For Sized types, this is the full buffer. For ?Sized types, one pointer-sized word is reserved for metadata (vtable or slice length).

Source§

impl<T, B: Buffer> Flat<T, B>

Source

pub fn new(val: T) -> Self

Constructs a Flat from a Sized value.

The value is stored at offset 0 with full buffer capacity.

§Panics
  • If size_of::<T>() exceeds B::CAPACITY.
  • If align_of::<T>() exceeds align_of::<usize>().
§Examples
use nexus_smartptr::{Flat, B32};

let f: Flat<u64, B32> = Flat::new(42);
assert_eq!(*f, 42);

Trait Implementations§

Source§

impl<T: ?Sized, B: Buffer> Deref for Flat<T, B>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl<T: ?Sized, B: Buffer> DerefMut for Flat<T, B>

Source§

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

Mutably dereferences the value.
Source§

impl<T: ?Sized, B: Buffer> Drop for Flat<T, B>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: ?Sized + Send, B: Buffer> Send for Flat<T, B>

Source§

impl<T: ?Sized + Sync, B: Buffer> Sync for Flat<T, B>

Auto Trait Implementations§

§

impl<T, B> Freeze for Flat<T, B>
where B: Freeze, T: ?Sized,

§

impl<T, B> RefUnwindSafe for Flat<T, B>

§

impl<T, B> Unpin for Flat<T, B>
where T: Unpin + ?Sized, B: Unpin,

§

impl<T, B> UnsafeUnpin for Flat<T, B>
where B: UnsafeUnpin, T: ?Sized,

§

impl<T, B> UnwindSafe for Flat<T, B>
where T: UnwindSafe + ?Sized, B: 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> 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.