Struct Attributes

Source
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>

Source

pub fn len(&self) -> usize

Counts the number of attributes

Source

pub fn is_empty(&self) -> bool

Checks whether this collection of attributes is empty

Source

pub fn is_class_member<B: AsRef<[u8]>>(&self, member: B) -> bool

Checks whether a given string is in the class names list

Source

pub fn get<B>(&self, key: B) -> Option<Option<&Bytes<'a>>>
where B: Into<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

Source

pub fn contains<B>(&self, key: B) -> bool
where B: Into<Bytes<'a>>,

Checks whether this attributes collection contains a given key

Source

pub fn remove<B>(&mut self, key: B) -> Option<Option<Bytes<'a>>>
where B: Into<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);
Source

pub fn remove_value<B>(&mut self, key: B) -> Option<Bytes<'a>>
where B: Into<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));
Source

pub fn get_mut<B>(&mut self, key: B) -> Option<Option<&mut Bytes<'a>>>
where B: Into<Bytes<'a>>,

Checks whether this attributes collection contains a given key and returns its value

Source

pub fn insert<K, V>(&mut self, key: K, value: Option<V>)
where K: Into<Bytes<'a>>, V: Into<Bytes<'a>>,

Inserts a new attribute into this attributes collection

Source

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

Source

pub fn id(&self) -> Option<&Bytes<'a>>

Returns the id attribute of this HTML tag, if present

Source

pub fn class(&self) -> Option<&Bytes<'a>>

Returns the class attribute of this HTML tag, if present

Source

pub fn class_iter(&self) -> Option<impl Iterator<Item = &str> + '_>

Returns an iterator over all of the class members

Source

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>

Source§

fn clone(&self) -> Attributes<'a>

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<'a> Debug for Attributes<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Attributes<'a>

§

impl<'a> RefUnwindSafe for Attributes<'a>

§

impl<'a> !Send for Attributes<'a>

§

impl<'a> !Sync for Attributes<'a>

§

impl<'a> Unpin for Attributes<'a>

§

impl<'a> UnwindSafe for Attributes<'a>

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