Skip to main content

Vector

Struct Vector 

Source
pub struct Vector<'scope, A: Allocator> { /* private fields */ }
Expand description

An exclusive scalar view, with no Deref, Clone or owning iterator.

Scalar slices cannot expose the Vec carrier to mem::take or mem::replace:

ⓘ
use ic_storage::with_vector;
let mut values = vec![17];
with_vector(&mut values, 512, |mut view| {
    let _: Vec<u64> = core::mem::take(view.values_mut());
});
ⓘ
use ic_storage::with_vector;
let mut values = vec![17];
with_vector(&mut values, 512, |mut view| {
    let _ = core::mem::replace(view.values_mut(), Vec::<u64>::new());
});

Borrowed elements cannot escape:

ⓘ
use ic_storage::with_vector;
let mut values = vec![17];
let escaped = with_vector(&mut values, 512, |view| view.values());

Consuming iteration cannot extract the carrier:

ⓘ
use ic_storage::with_vector;
let mut values = vec![17];
with_vector(&mut values, 512, |view| view.into_iter());

The view cannot clone an owning carrier:

ⓘ
use ic_storage::with_vector;
let mut values = vec![17];
with_vector(&mut values, 512, |view| view.clone());

Implementations§

Source§

impl<A: Allocator> Vector<'_, A>

Source

pub fn values(&self) -> &[u64]

Borrow only initialized scalar values, never spare capacity or the owner.

Source

pub fn values_mut(&mut self) -> &mut [u64]

Mutate non-owning scalar elements without changing vector ownership.

Source

pub fn push(&mut self, value: u64) -> Result<(), Refusal>

Append one scalar after checking the logical limit and reserving space.

Source

pub fn remove_first(&mut self) -> Option<u64>

Remove the first scalar, preserving the order of remaining values.

Source

pub fn shrink_to_fit(&mut self)

Ask the existing allocator to reduce spare capacity; no platform-page claim.

Source

pub fn clear(&mut self)

Remove all scalar elements while keeping the allocation available for reuse.

Auto Trait Implementations§

§

impl<'scope, A> !UnwindSafe for Vector<'scope, A>

§

impl<'scope, A> Forget for Vector<'scope, A>

§

impl<'scope, A> Freeze for Vector<'scope, A>
where &'scope mut Vec<u64, A>: Freeze,

§

impl<'scope, A> Move for Vector<'scope, A>

§

impl<'scope, A> RefUnwindSafe for Vector<'scope, A>
where &'scope mut Vec<u64, A>: RefUnwindSafe,

§

impl<'scope, A> Send for Vector<'scope, A>
where &'scope mut Vec<u64, A>: Send,

§

impl<'scope, A> Sync for Vector<'scope, A>
where &'scope mut Vec<u64, A>: Sync,

§

impl<'scope, A> Unpin for Vector<'scope, A>
where &'scope mut Vec<u64, A>: Unpin,

§

impl<'scope, A> UnsafeUnpin for Vector<'scope, A>
where &'scope mut Vec<u64, A>: UnsafeUnpin,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.