Skip to main content

Attributes

Struct Attributes 

Source
pub struct Attributes { /* private fields */ }
Expand description

A runtime collection of HTML attributes with unique keys.

Each key appears at most once. Inserting the same key again replaces its value. Attribute order is unspecified. Prefer constructing Attributes with the attributes! macro.

Keys and values are captured when inserted. The collection can be built separately from the element that renders it.

Implementations§

Source§

impl Attributes

Source

pub fn new() -> Self

Creates an empty attribute collection.

Prefer the attributes! macro when writing attributes directly. Use this constructor when the collection must be populated incrementally.

Source

pub fn with_capacity(capacity: usize) -> Self

Creates an empty attribute collection with space for at least capacity attributes.

Source

pub fn contains_key(&self, k: impl AsRef<str>) -> bool

Returns true if this collection contains an attribute with key k.

Source

pub fn get(&self, k: impl AsRef<str>) -> Option<&AttributeValue>

Returns the captured value stored for attribute key k, if present.

Source

pub fn insert( &mut self, cx: &Cx, k: impl AttributeKeyViewParts, v: impl AttributeValueViewParts, ) -> Option<AttributeValue>

Inserts or replaces an attribute.

Returns the previous value if the key was present. If v reports that its attribute should be omitted, stores AttributeValue::Absent. This still replaces the previous value and retains the key, but renders no attribute.

Source

pub fn remove(&mut self, k: impl AsRef<str>) -> Option<AttributeValue>

Removes an attribute, returning its captured value if the key was present.

Source

pub fn clear(&mut self)

Removes all attributes from the collection.

Source

pub fn extend( &mut self, iter: impl IntoIterator<Item = (AttributeKey, AttributeValue)>, )

Inserts every (key, value) entry from iter, replacing any keys already present.

Source

pub fn iter(&self) -> <&Self as IntoIterator>::IntoIter

Returns an iterator over attribute keys and captured values.

Trait Implementations§

Source§

impl AttributeViewParts for Attributes

Source§

fn into_view_parts(self, cx: &Cx, parts: &mut PartsWriter<'_>)

Appends zero or more attributes to the view being built.
Source§

impl Clone for Attributes

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Attributes

Source§

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

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

impl Default for Attributes

Source§

fn default() -> Self

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

impl IntoIterator for Attributes

Source§

type Item = (AttributeKey, AttributeValue)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<AttributeKey, AttributeValue>

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 Attributes

Source§

type Item = (&'a AttributeKey, &'a AttributeValue)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, AttributeKey, AttributeValue>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

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> CloneAny for T
where T: Any + Clone,

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

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.