Struct hamlet::attr::Attribute [] [src]

pub struct Attribute<'a> {
    pub name: Cow<'a, str>,
    pub value: Cow<'a, str>,
}

An HTML attribute.

Examples

let attr = hamlet::attr::Attribute::new("id", "foo");
assert_eq!(format!("{}", attr), "id=\"foo\"");

Fields

The attribute's name. The value of this field will not be validated, you must ensure it meets the requirements specified in the spec yourself.

Examples

let attr = hamlet::attr::Attribute::new("invalid=id", "foo");
assert_eq!(format!("{}", attr), "invalid=id=\"foo\"");

The attribute's value. This field will be escaped automatically, if it is an empty string then the attribute will be written with the 'Empty attribute syntax'.

Examples

let attr = hamlet::attr::Attribute::new("id", "bar & baz");
assert_eq!(format!("{}", attr), "id=\"bar &amp; baz\"");
let attr = hamlet::attr::Attribute::new("checked", "");
assert_eq!(format!("{}", attr), "checked");

Methods

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

Create an attribute, useful to avoid having to convert strings to Cow<str> yourself.

Generally this shouldn't be used directly by end users, it's likely that there are builder APIs or macros available that make attribute construction easier, for example the modification methods on AttributeList or the attrs! macro.

Examples

use std::borrow::Cow;
use hamlet::attr::Attribute;

let foo = "foo".to_owned();
let foo2 = foo.clone();
assert_eq!(
    Attribute::new("id", foo),
    Attribute {
        name: Cow::Borrowed("id"),
        value: Cow::Owned(foo2),
    });

Trait Implementations

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

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

Formats the value using the given formatter.

impl<'a> PartialEq for Attribute<'a>
[src]

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

This method tests for !=.

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

impl<'a> PartialOrd for Attribute<'a>
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'a> Ord for Attribute<'a>
[src]

This method returns an Ordering between self and other. Read more

impl<'a> Display for Attribute<'a>
[src]

Formats the value using the given formatter. Read more