Skip to main content

SharedVec

Struct SharedVec 

Source
pub struct SharedVec<T: Copy + 'static> { /* private fields */ }

Implementations§

Source§

impl<T: Copy + 'static> SharedVec<T>

Source

pub fn create(path: impl AsRef<Path>, capacity: usize) -> Result<Self, VecError>

Obtain the vec at path, initializing an empty one if the path does not yet exist and attaching to it if it does. Attaching leaves live elements and len in place; a region built with a different capacity is a LayoutMismatch. reset reinitializes.

Source

pub fn reset(path: impl AsRef<Path>, capacity: usize) -> Result<Self, VecError>

Truncate the vec at path and initialize an empty one, discarding every element live peers share. For a caller that knows it owns the path.

Source

pub fn open( path: impl AsRef<Path>, expected_capacity: usize, ) -> Result<Self, VecError>

Source

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.

Source

pub fn is_writable(&self) -> bool

Whether this mapping may be written.

Source

pub fn capacity(&self) -> usize

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

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.

Source

pub fn pop_back(&self) -> Option<T>

Remove and return the last element. Returns None when empty.

Source

pub fn get(&self, i: usize) -> Option<T>

Read the value at index i. Returns None when i >= len.

Source

pub fn set(&self, i: usize, v: T) -> Result<(), VecError>

Overwrite the value at index i. Returns Err(OutOfBounds) when i >= len.

Source

pub fn clear(&self)

Clear the vec by resetting len to 0. Slot payloads are not zeroed; they become unreachable through bounded indexing.

Source

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.

Source

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.

Source

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.

Source

pub fn flush(&self) -> Result<(), VecError>

Source

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

Trait Implementations§

Source§

impl<T: Copy + Send + Sync + 'static> AdaptiveInstance for SharedVec<T>

Source§

fn header(&self) -> &HandshakeHeader

Source§

fn ring(&self) -> &ObservationRing

Source§

fn make_policy(&self) -> Box<dyn Policy>

Source§

fn apply_migration(&self, new_tag: u32)

Called by the sidecar when the policy returns a new strategy tag. Default implementation: just set the tag on the header. Primitives that need heavier migration (data-layout swap) override this to perform the swap before (or after) updating the tag.
Source§

impl<T: Copy + Send + 'static> Send for SharedVec<T>

Source§

impl<T: Copy + Sync + 'static> Sync for SharedVec<T>

Auto Trait Implementations§

§

impl<T> !Freeze for SharedVec<T>

§

impl<T> !UnwindSafe for SharedVec<T>

§

impl<T> RefUnwindSafe for SharedVec<T>

§

impl<T> Unpin for SharedVec<T>
where PhantomData<T>: Unpin,

§

impl<T> UnsafeUnpin for SharedVec<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.