[−][src]Struct treeflection::keyed_context_vec::KeyedContextVec
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]
fn clone(&self) -> KeyedContextVec<T>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: Default> Default for KeyedContextVec<T>
[src]
fn default() -> KeyedContextVec<T>
[src]
impl<T> Deref for KeyedContextVec<T>
[src]
impl<T> DerefMut for KeyedContextVec<T>
[src]
impl<'de, T> Deserialize<'de> for KeyedContextVec<T> where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl<'a, T> Index<&'a str> for KeyedContextVec<T>
[src]
impl<T> Index<Range<usize>> for KeyedContextVec<T>
[src]
type Output = [T]
The returned type after indexing.
fn index(&self, index: Range<usize>) -> &[T]
[src]
impl<T> Index<RangeFrom<usize>> for KeyedContextVec<T>
[src]
type Output = [T]
The returned type after indexing.
fn index(&self, index: RangeFrom<usize>) -> &[T]
[src]
impl<T> Index<RangeFull> for KeyedContextVec<T>
[src]
impl<T> Index<RangeTo<usize>> for KeyedContextVec<T>
[src]
type Output = [T]
The returned type after indexing.
fn index(&self, index: RangeTo<usize>) -> &[T]
[src]
impl<T> Index<usize> for KeyedContextVec<T>
[src]
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]
T: Node + Serialize + DeserializeOwned + Default,
fn node_step(&mut self, runner: NodeRunner) -> String
[src]
impl<T> Serialize for KeyedContextVec<T> where
T: Serialize,
[src]
T: Serialize,
Auto Trait Implementations
impl<T> RefUnwindSafe for KeyedContextVec<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for KeyedContextVec<T> where
T: Send,
T: Send,
impl<T> Sync for KeyedContextVec<T> where
T: Sync,
T: Sync,
impl<T> Unpin for KeyedContextVec<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for KeyedContextVec<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,