pub struct Attributes<'a> { /* private fields */ }
Expand description
Stores all attributes of an HTML tag, as well as additional metadata such as id
and class
Implementations§
Source§impl<'a> Attributes<'a>
impl<'a> Attributes<'a>
Sourcepub fn is_class_member<B: AsRef<[u8]>>(&self, member: B) -> bool
pub fn is_class_member<B: AsRef<[u8]>>(&self, member: B) -> bool
Checks whether a given string is in the class names list
Sourcepub fn get<B>(&self, key: B) -> Option<Option<&Bytes<'a>>>
pub fn get<B>(&self, key: B) -> Option<Option<&Bytes<'a>>>
Checks whether this attributes collection contains a given key and returns its value
Attributes that exist in this tag but have no value set will have their inner Option set to None
Sourcepub fn contains<B>(&self, key: B) -> bool
pub fn contains<B>(&self, key: B) -> bool
Checks whether this attributes collection contains a given key
Sourcepub fn remove<B>(&mut self, key: B) -> Option<Option<Bytes<'a>>>
pub fn remove<B>(&mut self, key: B) -> Option<Option<Bytes<'a>>>
Removes an attribute from this collection and returns it.
As with Attributes::get()
, the outer Option is set to None if the attribute does not exist.
The inner option is set to None if the attribute exists but has no value.
§Example
let mut dom = tl::parse("<span contenteditable=\"true\"></span>", Default::default()).unwrap();
let element = dom.nodes_mut()[0].as_tag_mut().unwrap();
let attributes = element.attributes_mut();
assert_eq!(attributes.remove("contenteditable"), Some(Some("true".into())));
assert_eq!(attributes.len(), 0);
Sourcepub fn remove_value<B>(&mut self, key: B) -> Option<Bytes<'a>>
pub fn remove_value<B>(&mut self, key: B) -> Option<Bytes<'a>>
Removes the value of an attribute in this collection and returns it.
§Example
let mut dom = tl::parse("<span contenteditable=\"true\"></span>", Default::default()).unwrap();
let element = dom.nodes_mut()[0].as_tag_mut().unwrap();
let attributes = element.attributes_mut();
assert_eq!(attributes.remove_value("contenteditable"), Some("true".into()));
assert_eq!(attributes.get("contenteditable"), Some(None));
Sourcepub fn get_mut<B>(&mut self, key: B) -> Option<Option<&mut Bytes<'a>>>
pub fn get_mut<B>(&mut self, key: B) -> Option<Option<&mut Bytes<'a>>>
Checks whether this attributes collection contains a given key and returns its value
Sourcepub fn insert<K, V>(&mut self, key: K, value: Option<V>)
pub fn insert<K, V>(&mut self, key: K, value: Option<V>)
Inserts a new attribute into this attributes collection
Sourcepub fn iter(
&self,
) -> impl Iterator<Item = (Cow<'_, str>, Option<Cow<'_, str>>)> + '_
pub fn iter( &self, ) -> impl Iterator<Item = (Cow<'_, str>, Option<Cow<'_, str>>)> + '_
Returns an iterator (attribute_key, attribute_value)
over the attributes of this HTMLTag
Sourcepub fn class(&self) -> Option<&Bytes<'a>>
pub fn class(&self) -> Option<&Bytes<'a>>
Returns the class
attribute of this HTML tag, if present
Sourcepub fn class_iter(&self) -> Option<impl Iterator<Item = &str> + '_>
pub fn class_iter(&self) -> Option<impl Iterator<Item = &str> + '_>
Returns an iterator over all of the class members
Sourcepub fn unstable_raw(&self) -> &RawAttributesMap<'a>
pub fn unstable_raw(&self) -> &RawAttributesMap<'a>
Returns the underlying raw map for attributes
§A note on stability
It is not guaranteed for the returned map to include all attributes.
Some attributes may be stored in Attributes
itself and not in the raw map.
For that reason you should prefer to call methods on Attributes
directly,
i.e. Attributes::get()
to lookup an attribute by its key.
Trait Implementations§
Source§impl<'a> Clone for Attributes<'a>
impl<'a> Clone for Attributes<'a>
Source§fn clone(&self) -> Attributes<'a>
fn clone(&self) -> Attributes<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more