pub struct SharedVec<T: Copy + 'static> { /* private fields */ }Implementations§
pub fn create(path: impl AsRef<Path>, capacity: usize) -> Result<Self, VecError>
pub fn open( path: impl AsRef<Path>, expected_capacity: usize, ) -> Result<Self, VecError>
Sourcepub fn open_read_only(
path: impl AsRef<Path>,
expected_capacity: usize,
) -> Result<Self, VecError>
pub fn open_read_only( path: impl AsRef<Path>, expected_capacity: usize, ) -> Result<Self, VecError>
Open a vec this process may only read.
open needs a read+write file handle, which a
consumer of a privileged producer’s vec does not have - granting
it would let any reader corrupt the state for all of them.
Reads behave identically, under the same per-slot SeqLock;
writes return VecError::ReadOnly.
Sourcepub fn is_writable(&self) -> bool
pub fn is_writable(&self) -> bool
Whether this mapping may be written.
pub fn capacity(&self) -> usize
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn push_back(&self, v: T) -> Result<usize, VecError>
pub fn push_back(&self, v: T) -> Result<usize, VecError>
Append a value. Returns the index it landed at.
Returns Err(Full) when the vec is at capacity.
Sourcepub fn pop_back(&self) -> Option<T>
pub fn pop_back(&self) -> Option<T>
Remove and return the last element. Returns None when empty.
Sourcepub fn get(&self, i: usize) -> Option<T>
pub fn get(&self, i: usize) -> Option<T>
Read the value at index i. Returns None when i >= len.
Sourcepub fn set(&self, i: usize, v: T) -> Result<(), VecError>
pub fn set(&self, i: usize, v: T) -> Result<(), VecError>
Overwrite the value at index i. Returns Err(OutOfBounds)
when i >= len.
Sourcepub fn clear(&self)
pub fn clear(&self)
Clear the vec by resetting len to 0. Slot payloads are not zeroed; they become unreachable through bounded indexing.
Sourcepub fn snapshot(&self) -> Vec<T>
pub fn snapshot(&self) -> Vec<T>
Snapshot all current values into a Vec. Best-effort: under
concurrent writers, the snapshot is a consistent prefix at
the moment of the len load, with each slot read under its
own SeqLock.
Sourcepub fn for_each<F: FnMut(usize, &T)>(&self, f: F)
pub fn for_each<F: FnMut(usize, &T)>(&self, f: F)
Read every live slot in order and hand each to f, without
building a Vec.
For a consumer that looks at every element rather than keeping
them. snapshot costs an allocation the size
of the data plus a pass to fill it; this costs neither.
Each slot is read through its own SeqLock into a local, as get
does, so f never sees a torn value. A reference into the
mapping would let a writer change the bytes under the reader.
f is called in index order, over len as of entry.
Sourcepub fn for_each_range<F: FnMut(usize, &T)>(
&self,
start: usize,
end: usize,
f: F,
)
pub fn for_each_range<F: FnMut(usize, &T)>( &self, start: usize, end: usize, f: F, )
for_each over start..end, clamped to the
live length. The range form lets workers take disjoint spans
without materializing their share first.
pub fn flush(&self) -> Result<(), VecError>
Sourcepub fn flush_async(&self) -> Result<(), VecError>
pub fn flush_async(&self) -> Result<(), VecError>
Non-blocking flush: schedules a writeback via the OS. Note: Windows is only partially async (sync to page cache, not to disk).