Skip to main content

Attributes

Struct Attributes 

Source
pub struct Attributes(/* private fields */);
Expand description

A collection of Attribute entries associated with an element.

Implementations§

Source§

impl Attributes

Source

pub fn insert(&mut self, attribute: impl Into<Attribute>) -> Option<Attribute>

Available on crate feature write only.

Inserts the given attribute and returns the previous attribute with the same name, if any.

§Examples
  • Inserting a custom attribute into a detached spine entry:
let mut detached = DetachedEpubSpineEntry::new("c1");
let mut entry_mut = detached.as_mut();
let attributes = entry_mut.attributes_mut();

// Insert a custom vendor attribute
attributes.insert(("this:appearance", "omit"));

assert_eq!(Some("omit"), attributes.get_value("this:appearance"));
Source

pub fn by_name_mut(&mut self, name: &str) -> Option<&mut Attribute>

Available on crate feature write only.

Returns the mutable Attribute with the given name if present, otherwise None.

Source

pub fn iter_mut(&mut self) -> AttributesIterMut<'_>

Available on crate feature write only.

Returns an iterator over all mutable Attribute entries.

Source

pub fn remove(&mut self, name: &str) -> Option<Attribute>

Available on crate feature write only.

Removes and returns the attribute with the given name, if present.

Source

pub fn retain(&mut self, f: impl FnMut(&Attribute) -> bool)

Available on crate feature write only.

Retains only the attributes specified by the predicate.

If the closure returns false, the attribute is retained. Otherwise, the attribute is removed.

This method operates in place and visits every attribute exactly once.

§See Also
Source

pub fn extract_if( &mut self, f: impl FnMut(&Attribute) -> bool, ) -> impl Iterator<Item = Attribute>

Available on crate feature write only.

Removes and returns only the attributes specified by the predicate.

If the closure returns true, the attribute is removed and yielded. Otherwise, the attribute is retained.

§Drop

If the returned iterator is not exhausted, (e.g. dropped without iterating or iteration short-circuits), then the remaining attributes are retained.

Prefer Self::retain with a negated predicate if the returned iterator is not needed.

Source

pub fn drain(&mut self) -> impl Iterator<Item = Attribute>

Available on crate feature write only.

Removes and returns all attributes.

Source

pub fn clear(&mut self)

Available on crate feature write only.

Removes all attributes.

§See Also
  • Self::drain to get an iterator of the removed attributes.
Source§

impl Attributes

Source

pub fn len(&self) -> usize

The number of Attribute entries contained within.

Source

pub fn is_empty(&self) -> bool

Returns true if there are no attributes.

Source

pub fn get(&self, index: usize) -> Option<&Attribute>

Returns the associated Attribute if the given index is less than Self::len, otherwise None.

Source

pub fn iter(&self) -> AttributesIter<'_>

Returns an iterator over all Attribute entries.

Source

pub fn by_name(&self, name: &str) -> Option<&Attribute>

Returns the Attribute with the given name if present, otherwise None.

§See Also
Source

pub fn get_value(&self, name: &str) -> Option<&str>

Returns the value of the Attribute with the given name if present, otherwise None.

Source

pub fn has_name(&self, name: &str) -> bool

Returns true if an Attribute with the given name is present.

Trait Implementations§

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 Extend<Attribute> for Attributes

Available on crate feature write only.
Source§

fn extend<I: IntoIterator<Item = Attribute>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: T)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<'a> IntoIterator for &'a mut Attributes

Available on crate feature write only.
Source§

type Item = &'a mut Attribute

The type of the elements being iterated over.
Source§

type IntoIter = AttributesIterMut<'a>

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 Attribute

The type of the elements being iterated over.
Source§

type IntoIter = AttributesIter<'a>

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 PartialEq for Attributes

Source§

fn eq(&self, other: &Attributes) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Attributes

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