Skip to main content

MeteredVec

Struct MeteredVec 

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

A Vec whose every growth is charged to a Meter before it happens (its capacity, at heap_cost). Parsers build every table this way, so a table can never hold more than the meter granted, however many records the input declares; Self::into_parts hands the charge on to whatever keeps the table.

Implementations§

Source§

impl<T> MeteredVec<T>

Source

pub fn new(meter: &Arc<Meter>) -> Self

An empty vector charging meter.

Source

pub fn with_capacity(meter: &Arc<Meter>, n: usize) -> Result<Self, ChargeError>

An empty vector with room for exactly n, charged first.

Source

pub fn from_vec(vec: Vec<T>, meter: &Arc<Meter>) -> Result<Self, ChargeError>

Wraps a vector the caller already allocated (a TPK’s rows, a test’s), charging its capacity now. Parsers of input never use this: they grow a MeteredVec from empty.

Source

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

Removes the last element, retaining the charged capacity for reuse.

Source

pub fn from_charged_parts( vec: Vec<T>, charge: Charge, ) -> Result<Self, ChargeError>

Transfer a buffer and its existing charge without allocating or copying. Used by charged encoders. Any capacity not covered by the supplied charge is booked before accepting ownership, as with from_vec.

Source

pub fn as_slice(&self) -> &[T]

The elements.

Source

pub fn as_mut_slice(&mut self) -> &mut [T]

The elements, mutably (the length cannot grow through this).

Source

pub fn len(&self) -> usize

Number of elements.

Source

pub fn is_empty(&self) -> bool

Whether it is empty.

Source

pub fn capacity(&self) -> usize

The allocation, in elements.

Source

pub fn charge(&self) -> &Charge

The charge for the allocation.

Source

pub fn reserve(&mut self, additional: usize) -> Result<(), ChargeError>

Room for additional more, growing geometrically; charged first.

Source

pub fn reserve_exact(&mut self, additional: usize) -> Result<(), ChargeError>

Room for exactly additional more; charged first.

Source

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

Appends value, charging any growth first.

Source

pub fn truncate(&mut self, len: usize)

Cuts to len elements; the allocation and its charge stay.

Source

pub fn into_parts(self) -> (Vec<T>, Charge)

The vector and its charge, which must live as long as the vector’s allocation does.

Source

pub fn shrink_to_fit(&mut self) -> Result<(), ChargeError>

Gives back any spare capacity, the charge following it: shrunk in place, its charge cut after (no second block exists, so nothing more is charged); or, for a block that may be mapped given back below 128 KiB (super::shrink_moves; review round 13), moved into an exact allocation charged before it is made (both blocks exist while it moves), so a refusal leaves the vector as it was and nothing allocated beyond what was charged.

Source

pub fn into_boxed_slice(self) -> Result<(Box<[T]>, Charge), ChargeError>

The elements as a boxed slice, and its charge, with no spare capacity (Self::shrink_to_fit).

Source§

impl<T: Clone> MeteredVec<T>

Source

pub fn extend_from_slice(&mut self, items: &[T]) -> Result<(), ChargeError>

Appends a copy of items, charging any growth first.

Source§

impl MeteredVec<Value>

Source

pub fn push_built(&mut self, item: Built) -> Result<(), ChargeError>

Appends a built value (a list’s or a tuple’s item); this vector keeps its charge from then on. A refused growth drops both.

Source§

impl MeteredVec<(NodeId, Value)>

Source

pub fn push_entry( &mut self, key: NodeId, item: Built, ) -> Result<(), ChargeError>

Appends a dict entry whose value was built; this vector keeps its charge from then on. A refused growth drops both.

Source

pub fn set_entry(&mut self, pos: usize, item: Built) -> bool

Replaces the value of entry pos with a built one, keeping its key and position (a repeated name’s PyDict_SetItem, plan 3.10’s linear dict), and keeps its charge. The value replaced is dropped; its charge stays with this vector until it drops (charged, never under). False, with item dropped whole, when pos is not an entry.

Trait Implementations§

Source§

impl<T: Debug> Debug for MeteredVec<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for MeteredVec<T>

§

impl<T> !UnwindSafe for MeteredVec<T>

§

impl<T> Forget for MeteredVec<T>

§

impl<T> Freeze for MeteredVec<T>
where Vec<T>: Freeze,

§

impl<T> Move for MeteredVec<T>

§

impl<T> Send for MeteredVec<T>
where Vec<T>: Send,

§

impl<T> Sync for MeteredVec<T>
where Vec<T>: Sync,

§

impl<T> Unpin for MeteredVec<T>
where Vec<T>: Unpin,

§

impl<T> UnsafeUnpin for MeteredVec<T>
where Vec<T>: 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> Same for T

Source§

type Output = T

Should always be Self
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.