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: Cow<'a, str>
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: Cow<'a, str>
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 & baz\"");
let attr = hamlet::attr::Attribute::new("checked", ""); assert_eq!(format!("{}", attr), "checked");
Methods
impl<'a> Attribute<'a>
[src]
fn new<N, V>(name: N, value: V) -> Attribute<'a> where
N: Into<Cow<'a, str>>,
V: Into<Cow<'a, str>>,
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> Clone for Attribute<'a>
[src]
fn clone(&self) -> Attribute<'a>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<'a> Debug for Attribute<'a>
[src]
impl<'a> PartialEq for Attribute<'a>
[src]
fn eq(&self, __arg_0: &Attribute<'a>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Attribute<'a>) -> bool
This method tests for !=
.
impl<'a> Eq for Attribute<'a>
[src]
impl<'a> PartialOrd for Attribute<'a>
[src]
fn partial_cmp(&self, __arg_0: &Attribute<'a>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &Attribute<'a>) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &Attribute<'a>) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &Attribute<'a>) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &Attribute<'a>) -> bool
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]
fn cmp(&self, __arg_0: &Attribute<'a>) -> Ordering
This method returns an Ordering
between self
and other
. Read more