Struct hamlet::attr::AttributeList [] [src]

pub struct AttributeList<'a>(_);

A list of Attributes.

This is stored as a plain list instead of a set as in most cases it will be a small collection over which a linear search will be more efficient.

Methods

impl<'a> AttributeList<'a>
[src]

Return an empty AttributeList

Note that this does not check for duplicate attribute names. Generally, end users are not expected to call this method, and instead use high-level builder APIs or macros available to make construction easier, such as the provided attrs! macro.

Pull all attributes out of this collection, useful if you need to perform some more extensive modification.

use hamlet::attr::{ Attribute, AttributeList };
let attrs = attrs!(dataBar = "bar", dataBaz = "baz");

// Namespace all data attributes for some reason.
let attrs = AttributeList::from_vec(
    attrs.into_vec().into_iter()
        .map(|Attribute { name, value }| {
            Attribute::new(name.replace("data-", "data-foo-"), value)
        })
        .collect());

assert_eq!(attrs.get("data-foo-bar"), Some("bar"));

Try and get the value of an attribute.

Examples

let attrs = attrs!(id = "foo");
assert_eq!(attrs.get("id"), Some("foo"));
let attrs = attrs!(id = "foo");
assert_eq!(attrs.get("class"), None);

Unconditionally set an attribute to a value. If the attribute already exists in the list, update its value, otherwise add a new attribute to the list.

Examples

let mut attrs = attrs!(id = "foo");

attrs.set("id", "bar");

assert_eq!(attrs.get("id"), Some("bar"));
let mut attrs = attrs!(id = "foo");

attrs.set("class", "bar");

assert_eq!(attrs.get("class"), Some("bar"));

Removes and returns the attribute if there was one.

Examples

let mut attrs = attrs!(id = "foo");

assert_eq!(attrs.remove("id").map(|a| a.value).unwrap().as_ref(), "foo");

Returns an iterator over the list.

Trait Implementations

impl<'a> Clone for AttributeList<'a>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<'a> Debug for AttributeList<'a>
[src]

Formats the value using the given formatter.

impl<'a> Eq for AttributeList<'a>
[src]

impl<'a, 'b> PartialEq<AttributeList<'b>> for AttributeList<'a>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.