pub struct Flex<T: ?Sized, B: Buffer> { /* private fields */ }Expand description
Inline storage with heap fallback for ?Sized types.
Stores a trait object (or slice) inline when it fits, otherwise
heap-allocates. Use is_inline to query which
path was taken.
The total struct size equals size_of::<B>().
§Layout
The heap pointer slot doubles as the inline/heap discriminant (null = inline, non-null = heap address).
- ?Sized T:
[metadata(ptr)][heap_ptr(ptr)][value(B − 2*ptr)] - Sized T:
[heap_ptr(ptr)][value(B − ptr)]
Use the flex! macro for ?Sized construction,
or Flex::new for Sized types.
§Compile-time safety
Buffers too small for the overhead produce a compile error:
ⓘ
nexus_smartptr::define_buffer!(B8, 8);
trait Foo { fn foo(&self); }
struct Bar;
impl Foo for Bar { fn foo(&self) {} }
// B8 can't fit ?Sized overhead (metadata + heap pointer = 16 bytes).
let _: nexus_smartptr::Flex<dyn Foo, B8> = nexus_smartptr::flex!(Bar);Implementations§
Trait Implementations§
impl<T: ?Sized + Send, B: Buffer> Send for Flex<T, B>
impl<T: ?Sized + Sync, B: Buffer> Sync for Flex<T, B>
Auto Trait Implementations§
impl<T, B> Freeze for Flex<T, B>
impl<T, B> RefUnwindSafe for Flex<T, B>
impl<T, B> Unpin for Flex<T, B>
impl<T, B> UnsafeUnpin for Flex<T, B>where
B: UnsafeUnpin,
T: ?Sized,
impl<T, B> UnwindSafe for Flex<T, B>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more