FabricVec

Struct FabricVec 

Source
pub struct FabricVec<T> { /* private fields */ }
Expand description

A growable array stored in leased fabric memory.

Elements are serialized via postcard into fixed-size slots within the arena. The collection owns the underlying MemLease and releases it when dropped.

§Type parameters

T must implement Serialize + DeserializeOwned. The serialized form of each element must fit within stride - 4 bytes (4 bytes are used for the length prefix).

§Example

use grafos_collections::vec::FabricVec;
use grafos_std::mem::MemBuilder;

let mut v: FabricVec<u32> = FabricVec::with_capacity(100, 16)?;
v.push(&42)?;
v.push(&99)?;

for item in v.iter() {
    println!("{}", item?);
}

Implementations§

Source§

impl<T: Serialize + DeserializeOwned> FabricVec<T>

Source

pub fn new(lease: MemLease, stride: usize) -> Result<Self>

Create a new FabricVec that takes ownership of the given lease.

stride is the slot width in bytes. Each slot stores a 4-byte length prefix plus the postcard-serialized element, so the maximum serialized element size is stride - 4.

Capacity is computed as (arena_size - 24) / stride.

§Errors

Returns FabricError::CapacityExceeded if the arena is too small to hold even the 24-byte header.

Source

pub fn with_capacity(cap: usize, stride: usize) -> Result<Self>

Create a new FabricVec by acquiring a lease sized for cap elements of stride bytes each.

This is a convenience constructor that calls MemBuilder::new().min_bytes(...).acquire() and then FabricVec::new().

§Errors

Returns FabricError::CapacityExceeded if the host cannot provide an arena large enough for cap * stride + 24 bytes.

Source

pub fn push(&mut self, item: &T) -> Result<()>

Push an element onto the end of the vector.

If the vector is full, grow() is called to acquire a new memory lease and chain it. Returns FabricError::CapacityExceeded only if grow() fails (the host cannot allocate more memory).

Source

pub fn grow(&mut self) -> Result<()>

Acquire a new memory lease and chain it to this vector, increasing total capacity.

The new region has the same stride and approximately the same capacity as the primary region.

§Errors

Returns FabricError::CapacityExceeded if the host cannot allocate more memory.

Source

pub fn pop(&mut self) -> Result<Option<T>>

Remove and return the last element, or None if the vector is empty.

Source

pub fn get(&self, index: usize) -> Result<T>

Read the element at index.

§Errors

Returns FabricError::CapacityExceeded if index >= len.

Source

pub fn set(&mut self, index: usize, item: &T) -> Result<()>

Overwrite the element at index.

§Errors

Returns FabricError::CapacityExceeded if index >= len.

Source

pub fn len(&self) -> usize

Returns the number of elements in the vector.

Source

pub fn is_empty(&self) -> bool

Returns true if the vector contains no elements.

Source

pub fn capacity(&self) -> usize

Returns the maximum number of elements the vector can hold.

Source

pub fn clear(&mut self) -> Result<()>

Clear the vector, setting len to 0.

Source

pub fn iter(&self) -> FabricVecIter<'_, T>

Returns an iterator over the elements.

Source

pub fn lease_id(&self) -> u128

Returns the lease ID of the primary memory lease for external renewal management (e.g. via [grafos_leasekit::RenewalManager]).

Source

pub fn expires_at_unix_secs(&self) -> u64

Returns the expiry time (unix seconds) of the primary memory lease for external renewal management.

Auto Trait Implementations§

§

impl<T> Freeze for FabricVec<T>

§

impl<T> !RefUnwindSafe for FabricVec<T>

§

impl<T> !Send for FabricVec<T>

§

impl<T> !Sync for FabricVec<T>

§

impl<T> Unpin for FabricVec<T>
where T: Unpin,

§

impl<T> !UnwindSafe for FabricVec<T>

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