pub struct Attributes<'bp> {
pub value: Option<SmallIndex>,
/* private fields */
}Fields§
§value: Option<SmallIndex>Implementations§
Source§impl<'bp> Attributes<'bp>
impl<'bp> Attributes<'bp>
Sourcepub fn set(&mut self, key: &'bp str, value: impl Into<ValueKind<'bp>>)
pub fn set(&mut self, key: &'bp str, value: impl Into<ValueKind<'bp>>)
Set an attribute value.
let mut attributes = Attributes::empty();
attributes.set("name", "Nonsense");
attributes.get_as::<&str>("name").unwrap();Sourcepub fn value(&self) -> Option<&ValueKind<'bp>>
pub fn value(&self) -> Option<&ValueKind<'bp>>
Get the Value out of attributes.
This is always the first item
pub fn get(&self, key: &str) -> Option<&ValueKind<'bp>>
Sourcepub fn get_as<'a, T>(&'a self, key: &str) -> Option<T>
pub fn get_as<'a, T>(&'a self, key: &str) -> Option<T>
Get a value as a given type.
If the value doesn’t exist or can not be cast to the
expected type None is returned.
let mut attributes = Attributes::empty();
attributes.set("num", 123);
assert_eq!(attributes.get_as::<u32>("num").unwrap(), 123);
assert_eq!(attributes.get_as::<i16>("num").unwrap(), 123);Sourcepub fn iter_as<'a, T>(&'a self, key: &str) -> impl Iterator<Item = T>
pub fn iter_as<'a, T>(&'a self, key: &str) -> impl Iterator<Item = T>
Iterate over values of a given type
let mut attributes = Attributes::empty();
let values =
ValueKind::List([ValueKind::Int(1), ValueKind::Bool(true), ValueKind::Int(2)].into());
attributes.set("mixed_list", values);
let iter = attributes.iter_as::<u32>("mixed_list");
assert_eq!(vec![1u32, 2], iter.collect::<Vec<_>>());Trait Implementations§
Auto Trait Implementations§
impl<'bp> Freeze for Attributes<'bp>
impl<'bp> !RefUnwindSafe for Attributes<'bp>
impl<'bp> !Send for Attributes<'bp>
impl<'bp> !Sync for Attributes<'bp>
impl<'bp> Unpin for Attributes<'bp>
impl<'bp> !UnwindSafe for Attributes<'bp>
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