Skip to main content

Variables

Struct Variables 

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

Ordered map of variable names to values, shared on clone.

Iteration follows insertion order; inserting an existing name replaces its value in place. Cloning is a reference-count bump and an empty map holds no allocation. Lookups scan the entries, so the map suits the handful of variables a node produces, not large dictionaries (use a Value::Object for those).

use graphrt_core::variables::Variables;
use graphrt_core::Value;

let mut outputs = Variables::new();
outputs.insert("text", Value::from("hi"));
let shared = outputs.clone(); // no copy
assert_eq!(shared.get("text"), Some(&Value::from("hi")));
assert_eq!(outputs["missing"], Value::Null);

Implementations§

Source§

impl Variables

Source

pub const fn new() -> Self

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn get(&self, name: &str) -> Option<&Value>

Source

pub fn get_key_value(&self, name: &str) -> Option<(&VarName, &Value)>

Source

pub fn get_mut(&mut self, name: &str) -> Option<&mut Value>

Mutable access to a value (copies the entries first if they are shared).

Source

pub fn contains_key(&self, name: &str) -> bool

Source

pub fn insert( &mut self, name: impl Into<VarName>, value: Value, ) -> Option<Value>

Insert or replace. A replaced value keeps its position and is returned.

Source

pub fn insert_str(&mut self, name: &str, value: Value) -> Option<Value>

Variables::insert for a borrowed name: the name is only copied when it is new, so overwriting an existing variable allocates nothing.

Source

pub fn remove(&mut self, name: &str) -> Option<Value>

Remove a variable, keeping the order of the others.

Source

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

Reserve room for additional more entries.

Source

pub fn iter(&self) -> Iter<'_> ⓘ

(name, value) pairs in insertion order.

Source

pub fn keys( &self, ) -> impl DoubleEndedIterator<Item = &str> + ExactSizeIterator + '_

Source

pub fn values( &self, ) -> impl DoubleEndedIterator<Item = &Value> + ExactSizeIterator + '_

Source

pub fn ptr_eq(&self, other: &Self) -> bool

Whether both maps share the same storage (a clone of one another, unchanged since).

Source

pub fn to_index_map(&self) -> IndexMap<String, Value>

Copy into an IndexMap with owned names.

Trait Implementations§

Source§

impl Clone for Variables

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Variables

Source§

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

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

impl Default for Variables

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Variables

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<K: Into<VarName>> Extend<(K, Value)> for Variables

Source§

fn extend<I: IntoIterator<Item = (K, Value)>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: T)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl From<IndexMap<String, Value>> for Variables

Source§

fn from(map: IndexMap<String, Value>) -> Self

Converts to this type from the input type.
Source§

impl From<Variables> for IndexMap<String, Value>

Source§

fn from(variables: Variables) -> Self

Converts to this type from the input type.
Source§

impl<K: Into<VarName>, const N: usize> From<[(K, Value); N]> for Variables

Source§

fn from(entries: [(K, Value); N]) -> Self

Converts to this type from the input type.
Source§

impl<K: Into<VarName>> FromIterator<(K, Value)> for Variables

Source§

fn from_iter<I: IntoIterator<Item = (K, Value)>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl Index<&str> for Variables

Indexing a missing name yields Value::Null instead of panicking.

Source§

type Output = Value

The returned type after indexing.
Source§

fn index(&self, name: &str) -> &Value

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a> IntoIterator for &'a Variables

Source§

type Item = (&'a str, &'a Value)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Iter<'a> ⓘ

Creates an iterator from a value. Read more
Source§

impl IntoIterator for Variables

Source§

type Item = (VarName, Value)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> IntoIter ⓘ

Creates an iterator from a value. Read more
Source§

impl PartialEq for Variables

Map equality: the same names with equal values, in any order.

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Variables

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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

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.