[][src]Struct treeflection::keyed_context_vec::KeyedContextVec

pub struct KeyedContextVec<T> { /* fields omitted */ }

Implementations

impl<T> KeyedContextVec<T>[src]

A KeyedContextVec is a ContextVec with the added ability to access elements via String keys.

The purpose of a ContextVec is to provide a way for commands to easily access relevant values. If we have a ContextVec named foo, the command foo[?] get will display the values in foo that the context points to.

Contents

  • vector: Vec<T>
  • context: Vec<usize>

Invariants

  • the values in context will point to a valid value in vector
  • the values in context will continue to point to the same value in vector (even after operations like insert and remove)
  • key values are not reused
  • keys.len() == vector.len()

pub fn new() -> KeyedContextVec<T>[src]

Create a new empty KeyedContextVec

pub fn from_vec(pairs: Vec<(String, T)>) -> KeyedContextVec<T>[src]

Create a new KeyedContextVec from a Vec

pub fn selection_first(&self) -> Option<&T>[src]

Get the value currently pointed to by context

pub fn selection_first_mut(&mut self) -> Option<&mut T>[src]

Mutably get the value currently pointed to by context

pub fn selection(&self) -> Vec<&T>[src]

Get the values currently pointed to by context

pub fn get_context(&self) -> &[usize][src]

Get a slice of the context

pub fn into_context(self) -> Vec<usize>[src]

Consume the KeyedContextVec into the context

pub fn into_vector(self) -> Vec<T>[src]

Consume the KeyedContextVec into the vector

pub fn into_tuple(self) -> (Vec<usize>, Vec<String>, Vec<T>)[src]

Consume the KeyedContextVec into a tuple of the context, keys and the vector

pub fn clear_context(&mut self)[src]

Clears the context

pub fn set_context(&mut self, value: usize)[src]

Sets a new context

pub fn set_context_vec(&mut self, values: Vec<usize>)[src]

Sets a new context

pub fn set_vec(&mut self, pairs: Vec<(String, T)>)[src]

Set to a new vector. Clears the context.

pub fn clear(&mut self)[src]

Clears the keys/values and the context

pub fn push(&mut self, key: String, value: T)[src]

Push a value to the end of the vector

pub fn insert(&mut self, index: usize, key: String, value: T)[src]

Insert a value into the vector. Invalid context indices are updated.

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

Pop a value from the end of the vector. If it succeeds invalid context indices are removed.

pub fn remove(&mut self, to_remove: usize) -> T[src]

Remove a value at the specified index. Deletes any context indices pointing to the removed value. Shifts all larger context indices down.

pub fn key_to_value(&self, key_search: &str) -> Option<&T>[src]

Retrieve the index corresponding to the given key This operation is O(n)

pub fn key_to_value_mut(&mut self, key_search: &str) -> Option<&mut T>[src]

Retrieve the index corresponding to the given key This operation is O(n)

pub fn index_to_key(&self, i: usize) -> Option<String>[src]

Retrive the key corresponding to the given index

pub fn key_to_index(&self, key_search: &str) -> Option<usize>[src]

Retrieve the index corresponding to the given key This operation is O(n)

pub fn key_value_iter(&self) -> Zip<Iter<String>, Iter<T>>[src]

Iterate over key/value pairs

pub fn key_iter(&self) -> Iter<String>[src]

Iterate over keys

pub fn keys(&self) -> Vec<String>[src]

Create a vector of keys

pub fn contains_key(&self, key: &String) -> bool[src]

Returns true if the passed key is used

Trait Implementations

impl<T: Clone> Clone for KeyedContextVec<T>[src]

impl<T: Default> Default for KeyedContextVec<T>[src]

impl<T> Deref for KeyedContextVec<T>[src]

type Target = [T]

The resulting type after dereferencing.

impl<T> DerefMut for KeyedContextVec<T>[src]

impl<'de, T> Deserialize<'de> for KeyedContextVec<T> where
    T: Deserialize<'de>, 
[src]

impl<'a, T> Index<&'a str> for KeyedContextVec<T>[src]

type Output = T

The returned type after indexing.

impl<T> Index<Range<usize>> for KeyedContextVec<T>[src]

type Output = [T]

The returned type after indexing.

impl<T> Index<RangeFrom<usize>> for KeyedContextVec<T>[src]

type Output = [T]

The returned type after indexing.

impl<T> Index<RangeFull> for KeyedContextVec<T>[src]

type Output = [T]

The returned type after indexing.

impl<T> Index<RangeTo<usize>> for KeyedContextVec<T>[src]

type Output = [T]

The returned type after indexing.

impl<T> Index<usize> for KeyedContextVec<T>[src]

type Output = T

The returned type after indexing.

impl<'a, T> IndexMut<&'a str> for KeyedContextVec<T>[src]

impl<T> IndexMut<Range<usize>> for KeyedContextVec<T>[src]

impl<T> IndexMut<RangeFrom<usize>> for KeyedContextVec<T>[src]

impl<T> IndexMut<RangeFull> for KeyedContextVec<T>[src]

impl<T> IndexMut<RangeTo<usize>> for KeyedContextVec<T>[src]

impl<T> IndexMut<usize> for KeyedContextVec<T>[src]

impl<T> Node for KeyedContextVec<T> where
    T: Node + Serialize + DeserializeOwned + Default
[src]

impl<T> Serialize for KeyedContextVec<T> where
    T: Serialize
[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for KeyedContextVec<T> where
    T: RefUnwindSafe

impl<T> Send for KeyedContextVec<T> where
    T: Send

impl<T> Sync for KeyedContextVec<T> where
    T: Sync

impl<T> Unpin for KeyedContextVec<T> where
    T: Unpin

impl<T> UnwindSafe for KeyedContextVec<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.