[][src]Struct quick_xml::events::attributes::Attribute

pub struct Attribute<'a> {
    pub key: &'a [u8],
    pub value: Cow<'a, [u8]>,
}

A struct representing a key/value XML attribute.

Field value stores raw bytes, possibly containing escape-sequences. Most users will likely want to access the value using one of the unescaped_value and unescape_and_decode_value functions.

Fields

key: &'a [u8]

The key to uniquely define the attribute.

If Attributes::with_checks is turned off, the key might not be unique.

value: Cow<'a, [u8]>

The raw value of the attribute.

Implementations

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

pub fn unescaped_value(&self) -> Result<Cow<'_, [u8]>>[src]

Returns the unescaped value.

This is normally the value you are interested in. Escape sequences such as &gt; are replaced with their unescaped equivalents such as >.

This will allocate if the value contains any escape sequences.

pub fn unescape_and_decode_value<B: BufRead>(
    &self,
    reader: &Reader<B>
) -> Result<String>
[src]

Decode then unescapes the value

This allocates a String in all cases. For performance reasons it might be a better idea to instead use one of:

  • Reader::decode(), as it only allocates when the decoding can't be performed otherwise.
  • unescaped_value(), as it doesn't allocate when no escape sequences are used.

pub fn unescape_and_decode_without_bom<B: BufRead>(
    &self,
    reader: &Reader<B>
) -> Result<String>
[src]

helper method to unescape then decode self using the reader encoding but without BOM (Byte order mark)

for performance reasons (could avoid allocating a String), it might be wiser to manually use

  1. BytesText::unescaped()
  2. Reader::decode(...)

Trait Implementations

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

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

impl<'a> From<(&'a [u8], &'a [u8])> for Attribute<'a>[src]

fn from(val: (&'a [u8], &'a [u8])) -> Attribute<'a>[src]

Creates new attribute from raw bytes. Does not apply any transformation to both key and value.

Examples

use quick_xml::events::attributes::Attribute;

let features = Attribute::from(("features".as_bytes(), "Bells &amp; whistles".as_bytes()));
assert_eq!(features.value, "Bells &amp; whistles".as_bytes());

impl<'a> From<(&'a str, &'a str)> for Attribute<'a>[src]

fn from(val: (&'a str, &'a str)) -> Attribute<'a>[src]

Creates new attribute from text representation. Key is stored as-is, but the value will be escaped.

Examples

use quick_xml::events::attributes::Attribute;

let features = Attribute::from(("features", "Bells & whistles"));
assert_eq!(features.value, "Bells &amp; whistles".as_bytes());

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

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

Auto Trait Implementations

impl<'a> RefUnwindSafe for Attribute<'a>

impl<'a> Send for Attribute<'a>

impl<'a> Sync for Attribute<'a>

impl<'a> Unpin for Attribute<'a>

impl<'a> UnwindSafe for Attribute<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.