VarNameMap

Struct VarNameMap 

Source
pub struct VarNameMap { /* private fields */ }
Expand description

Bi-directional mapping between variables and names, intended for the implementation of a Manager.

The map requires variable names to be unique, but allows unnamed variables (represented by empty strings).

Implementations§

Source§

impl VarNameMap

Source

pub fn new() -> Self

Create an empty map

Source

pub fn len(&self) -> VarNo

Get the number of variables (including unnamed ones)

Source

pub fn is_empty(&self) -> bool

true if and only if self.len() is 0

Source

pub fn reserve(&mut self, additional: VarNo)

Reserve space for additional entries

Adding the next additional entries will not cause an allocation in the underlying vector and map.

Source

pub fn named_count(&self) -> VarNo

Get the number of named variables

Source

pub fn add_unnamed(&mut self, additional: VarNo)

Add additional unnamed variables

Panics if self.len() plus additional is greater than to VarNo::MAX.

Source

pub fn add_named<T: IntoIterator<Item = S>, S: Into<String>>( &mut self, names: T, ) -> Result<Range<VarNo>, DuplicateVarName>

Add fresh variables with names from names

Returns Ok(range) on success, where range contains the new variable numbers. If names is too long (there would be more than VarNo::MAX variables), the remaining elements are not consumed.

If a variable name is not unique, this method returns a DuplicateVarName error.

Source

pub fn get_or_add(&mut self, name: impl Into<String>) -> (VarNo, bool)

Get the variable number for the given name if present, or add a new variable

Returns a pair (var_no, found). If the provided variable name is empty, this method will always create a fresh variable.

If a variable with the given name is not present yet, and there is no variable free in range 0..VarNo::MAX, then the variable is not added. Still, the return value is VarNo::MAX.

Source

pub fn name_to_var(&self, name: impl AsRef<str>) -> Option<VarNo>

Get the variable number for the given name, if present

self.name_to_var("") always returns None.

Source

pub fn var_name(&self, var: VarNo) -> &str

Get var’s name

For unnamed vars, this will return the empty string.

Panics if var is greater or equal to self.len().

Source

pub fn set_var_name( &mut self, var: VarNo, name: impl Into<String>, ) -> Result<(), DuplicateVarName>

Label var as name

An empty name means that the variable will become unnamed, and cannot be retrieved via Self::name_to_var() anymore.

Returns Err((name, other_var)) if name is not unique (and not "").

Panics if var is greater or equal to the number of variables in this map.

Source

pub fn into_names_iter(self) -> IntoNamesIter

Iterate over the variable names (including all unnamed variables)

Trait Implementations§

Source§

impl Clone for VarNameMap

Source§

fn clone(&self) -> VarNameMap

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VarNameMap

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for VarNameMap

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for VarNameMap

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.