Skip to main content

Attributes

Struct Attributes 

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

A runtime collection of HTML attributes with unique keys.

Attributes is map-like: each key appears at most once, and inserting the same key again replaces the previous value. Do not rely on render order. Prefer constructing Attributes with the attributes! macro.

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.

Prefer the attributes! macro when writing attributes directly. This is mainly useful for generated code or manual builders that already know how many attributes they will insert.

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<&ViewPart>

Returns the view parts stored for attribute key k, if present.

Source

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

Inserts or replaces an attribute.

The value is converted with AttributeValueViewParts. If the key was already present, the previous rendered value is returned. If the implementation of AttributeValueViewParts for v signals that the attribute should not be present, ViewPart::empty will be used as the value instead, which call cause the previous value to be removed and the attribute will not be rendered in a view!.

Source

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

Removes an attribute, returning its rendered 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 = (String, ViewPart)>)

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 rendered 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) -> Attributes

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() -> Attributes

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

impl IntoIterator for Attributes

Source§

type Item = (String, ViewPart)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<String, ViewPart>

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 String, &'a ViewPart)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, String, ViewPart>

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