Struct liquid_core::model::map::Object

source ·
pub struct Object { /* private fields */ }
Expand description

Type representing a Liquid object, payload of the Value::Object variant

Implementations§

source§

impl Object

source

pub fn new() -> Self

Makes a new empty Object.

source

pub fn clear(&mut self)

Clears the map, removing all values.

source

pub fn get<Q>(&self, key: &Q) -> Option<&Value>where KString: Borrow<Q>, Q: Ord + Eq + Hash + ?Sized,

Returns a reference to the value corresponding to the key.

The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

source

pub fn contains_key<Q>(&self, key: &Q) -> boolwhere KString: Borrow<Q>, Q: Ord + Eq + Hash + ?Sized,

Returns true if the map contains a value for the specified key.

The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

source

pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut Value>where KString: Borrow<Q>, Q: Ord + Eq + Hash + ?Sized,

Returns a mutable reference to the value corresponding to the key.

The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

source

pub fn insert(&mut self, k: KString, v: Value) -> Option<Value>

Inserts a key-value pair into the map.

If the map did not have this key present, None is returned.

If the map did have this key present, the value is updated, and the old value is returned.

source

pub fn remove<Q>(&mut self, key: &Q) -> Option<Value>where KString: Borrow<Q>, Q: Ord + Eq + Hash + ?Sized,

Removes a key from the map, returning the value at the key if the key was previously in the map.

The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

source

pub fn entry<S>(&mut self, key: S) -> Entry<'_>where S: Into<KString>,

Gets the given key’s corresponding entry in the map for in-place manipulation.

source

pub fn len(&self) -> usize

Returns the number of elements in the map.

source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

source

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

Gets an iterator over the entries of the map.

source

pub fn iter_mut(&mut self) -> IterMut<'_>

Gets a mutable iterator over the entries of the map.

source

pub fn keys(&self) -> Keys<'_>

Gets an iterator over the keys of the map.

source

pub fn values(&self) -> Values<'_>

Gets an iterator over the values of the map.

source

pub fn values_mut(&mut self) -> ValuesMut<'_>

Gets an iterator over mutable values of the map.

Trait Implementations§

source§

impl Clone for Object

source§

fn clone(&self) -> Object

Returns a copy 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 Object

source§

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

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

impl Default for Object

source§

fn default() -> Object

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

impl<'de> Deserialize<'de> for Object

source§

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

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

impl Extend<(KStringBase<Box<str, Global>>, Value)> for Object

source§

fn extend<T>(&mut self, iter: T)where T: IntoIterator<Item = (KString, Value)>,

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

fn extend_one(&mut self, item: A)

🔬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<Object> for Value

source§

fn from(other: Object) -> Self

Converts to this type from the input type.
source§

impl From<Object> for ValueCow<'static>

source§

fn from(other: Object) -> Self

Converts to this type from the input type.
source§

impl FromIterator<(KStringBase<Box<str, Global>>, Value)> for Object

source§

fn from_iter<T>(iter: T) -> Selfwhere T: IntoIterator<Item = (KString, Value)>,

Creates a value from an iterator. Read more
source§

impl<'a, Q> Index<&'a Q> for Objectwhere KString: Borrow<Q>, Q: Ord + Eq + Hash + ?Sized,

Access an element of this map. Panics if the given key is not present in the map.

match *val {
    Value::Scalar(ref s) => Some(s.to_kstr()),
    Value::Array(ref arr) => Some(arr[0].to_kstr()),
    Value::Object(ref map) => Some(map["type"].to_kstr()),
    _ => None,
}
§

type Output = Value

The returned type after indexing.
source§

fn index(&self, index: &Q) -> &Value

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

impl<'a, Q> IndexMut<&'a Q> for Objectwhere KString: Borrow<Q>, Q: Ord + Eq + Hash + ?Sized,

Mutably access an element of this map. Panics if the given key is not present in the map.

map["key"] = liquid_core::value!("value");
source§

fn index_mut(&mut self, index: &Q) -> &mut Value

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

impl<'a> IntoIterator for &'a Object

§

type Item = (&'a KStringBase<Box<str, Global>>, &'a Value)

The type of the elements being iterated over.
§

type IntoIter = Iter<'a>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a> IntoIterator for &'a mut Object

§

type Item = (&'a KStringBase<Box<str, Global>>, &'a mut Value)

The type of the elements being iterated over.
§

type IntoIter = IterMut<'a>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl IntoIterator for Object

§

type Item = (KStringBase<Box<str, Global>>, Value)

The type of the elements being iterated over.
§

type IntoIter = IntoIter

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl ObjectView for Object

source§

fn as_value(&self) -> &dyn ValueView

Cast to ValueView
source§

fn size(&self) -> i64

Returns the number of elements.
source§

fn keys<'k>(&'k self) -> Box<dyn Iterator<Item = KStringCow<'k>> + 'k>

Keys available for lookup.
source§

fn values<'k>(&'k self) -> Box<dyn Iterator<Item = &'k dyn ValueView> + 'k>

Keys available for lookup.
source§

fn iter<'k>( &'k self ) -> Box<dyn Iterator<Item = (KStringCow<'k>, &'k dyn ValueView)> + 'k>

Returns an iterator .
source§

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

Access a contained BoxedValue.
source§

fn get<'s>(&'s self, index: &str) -> Option<&'s dyn ValueView>

Access a contained Value.
source§

impl PartialEq<Object> for Object

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Object

source§

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

Serialize this value into the given Serde serializer. Read more
source§

impl ValueView for Object

source§

fn as_debug(&self) -> &dyn Debug

Get a Debug representation
source§

fn render(&self) -> DisplayCow<'_>

A Display for a BoxedValue rendered for the user.
source§

fn source(&self) -> DisplayCow<'_>

A Display for a Value as source code.
source§

fn type_name(&self) -> &'static str

Report the data type (generally for error reporting).
source§

fn query_state(&self, state: State) -> bool

Query the value’s state
source§

fn to_kstr(&self) -> KStringCow<'_>

Interpret as a string.
source§

fn to_value(&self) -> Value

Convert to an owned type.
source§

fn as_object(&self) -> Option<&dyn ObjectView>

Extracts the object value if it is a object.
source§

fn as_scalar(&self) -> Option<ScalarCow<'_>>

Extracts the scalar value if it is a scalar.
source§

fn is_scalar(&self) -> bool

Tests whether this value is a scalar
source§

fn as_array(&self) -> Option<&dyn ArrayView>

Extracts the array value if it is an array.
source§

fn is_array(&self) -> bool

Tests whether this value is an array
source§

fn is_object(&self) -> bool

Tests whether this value is an object
source§

fn as_state(&self) -> Option<State>

Extracts the state if it is one
source§

fn is_state(&self) -> bool

Tests whether this value is state
source§

fn is_nil(&self) -> bool

Tests whether this value is nil Read more
source§

impl Eq for Object

source§

impl StructuralEq for Object

source§

impl StructuralPartialEq for Object

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
source§

impl<T> Any for Twhere T: Any,

source§

impl<T> CloneAny for Twhere T: Any + Clone,

source§

impl<T> CloneAnySend for Twhere T: Any + Send + Clone,

source§

impl<T> CloneAnySendSync for Twhere T: Any + Send + Sync + Clone,

source§

impl<T> CloneAnySync for Twhere T: Any + Sync + Clone,

source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,