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

name

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\"");
value

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>

fn new<N, V>(name: N, value: V) -> Attribute<'a> where N: Into<Cow<'a, str>>, V: Into<Cow<'a, str>>

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> Display for Attribute<'a>

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

Derived Implementations

impl<'a> Ord for Attribute<'a>

fn cmp(&self, __arg_0: &Attribute<'a>) -> Ordering

impl<'a> PartialOrd for Attribute<'a>

fn partial_cmp(&self, __arg_0: &Attribute<'a>) -> Option<Ordering>

fn lt(&self, __arg_0: &Attribute<'a>) -> bool

fn le(&self, __arg_0: &Attribute<'a>) -> bool

fn gt(&self, __arg_0: &Attribute<'a>) -> bool

fn ge(&self, __arg_0: &Attribute<'a>) -> bool

impl<'a> Eq for Attribute<'a>

impl<'a> PartialEq for Attribute<'a>

fn eq(&self, __arg_0: &Attribute<'a>) -> bool

fn ne(&self, __arg_0: &Attribute<'a>) -> bool

impl<'a> Debug for Attribute<'a>

fn fmt(&self, __arg_0: &mut Formatter) -> Result

impl<'a> Clone for Attribute<'a>

fn clone(&self) -> Attribute<'a>

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