Struct liquid_core::model::map::OccupiedEntry
source · pub struct OccupiedEntry<'a> { /* private fields */ }Expand description
An occupied Entry. It is part of the Entry enum.
Implementations§
source§impl<'a> OccupiedEntry<'a>
impl<'a> OccupiedEntry<'a>
sourcepub fn key(&self) -> &KString
pub fn key(&self) -> &KString
Gets a reference to the key in the entry.
§Examples
use liquid_core::model::map::Entry;
let mut map = liquid_core::model::Object::new();
map.insert("liquid".into(), liquid_core::value!(12));
match map.entry("liquid") {
Entry::Occupied(occupied) => {
assert_eq!(occupied.key(), &"liquid");
}
Entry::Vacant(_) => unimplemented!(),
}sourcepub fn get(&self) -> &Value
pub fn get(&self) -> &Value
Gets a reference to the value in the entry.
§Examples
use liquid_core::model::map::Entry;
let mut map = liquid_core::model::Object::new();
map.insert("liquid".into(), liquid_core::value!(12));
match map.entry("liquid") {
Entry::Occupied(occupied) => {
assert_eq!(occupied.get(), &liquid_core::value!(12));
}
Entry::Vacant(_) => unimplemented!(),
}sourcepub fn get_mut(&mut self) -> &mut Value
pub fn get_mut(&mut self) -> &mut Value
Gets a mutable reference to the value in the entry.
§Examples
use liquid_core::model::map::Entry;
let mut map = liquid_core::model::Object::new();
map.insert("liquid".into(), liquid_core::value!([1, 2, 3]));
match map.entry("liquid") {
Entry::Occupied(mut occupied) => {
occupied.get_mut().as_array().unwrap();
}
Entry::Vacant(_) => unimplemented!(),
}sourcepub fn into_mut(self) -> &'a mut Value
pub fn into_mut(self) -> &'a mut Value
Converts the entry into a mutable reference to its value.
§Examples
use liquid_core::model::map::Entry;
let mut map = liquid_core::model::Object::new();
map.insert("liquid".into(), liquid_core::value!([1, 2, 3]));
match map.entry("liquid") {
Entry::Occupied(mut occupied) => {
occupied.into_mut().as_array().unwrap();
}
Entry::Vacant(_) => unimplemented!(),
}sourcepub fn insert(&mut self, value: Value) -> Value
pub fn insert(&mut self, value: Value) -> Value
Sets the value of the entry with the OccupiedEntry’s key, and returns
the entry’s old value.
§Examples
use liquid_core::model::map::Entry;
let mut map = liquid_core::model::Object::new();
map.insert("liquid".into(), liquid_core::value!(12));
match map.entry("liquid") {
Entry::Occupied(mut occupied) => {
assert_eq!(occupied.insert(liquid_core::value!(13)), liquid_core::value!(12));
assert_eq!(occupied.get(), &liquid_core::value!(13));
}
Entry::Vacant(_) => unimplemented!(),
}sourcepub fn remove(self) -> Value
pub fn remove(self) -> Value
Takes the value of the entry out of the map, and returns it.
§Examples
use liquid_core::model::map::Entry;
let mut map = liquid_core::model::Object::new();
map.insert("liquid".into(), liquid_core::value!(12));
match map.entry("liquid") {
Entry::Occupied(occupied) => {
assert_eq!(occupied.remove(), liquid_core::value!(12));
}
Entry::Vacant(_) => unimplemented!(),
}Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for OccupiedEntry<'a>
impl<'a> RefUnwindSafe for OccupiedEntry<'a>
impl<'a> Send for OccupiedEntry<'a>
impl<'a> Sync for OccupiedEntry<'a>
impl<'a> Unpin for OccupiedEntry<'a>
impl<'a> !UnwindSafe for OccupiedEntry<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more