AttributeElementExt

Trait AttributeElementExt 

Source
pub trait AttributeElementExt {
    // Required method
    fn try_attribute<F>(&self, attr_name: &str) -> Result<F, Error>
       where F: FromStr,
             F::Err: Error + Send + Sync + 'static;

    // Provided method
    fn attribute<F>(&self, attr_name: &str) -> Option<F>
       where F: FromStr,
             F::Err: Error + Send + Sync + 'static { ... }
}
Expand description

Get an attribute from an element.

Required Methods§

Source

fn try_attribute<F>(&self, attr_name: &str) -> Result<F, Error>
where F: FromStr, F::Err: Error + Send + Sync + 'static,

Try to get an attribute from its name and return a Result.

The type of the return value is chosen by the caller, as long as this type can be parsed from &str.

Provided Methods§

Source

fn attribute<F>(&self, attr_name: &str) -> Option<F>
where F: FromStr, F::Err: Error + Send + Sync + 'static,

Get an attribute from its name if present and return a Option.

The type of the return value is chosen by the caller, as long as this type can be parsed from &str.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl AttributeElementExt for Element

Source§

fn try_attribute<F>(&self, attr_name: &str) -> Result<F, Error>
where F: FromStr, F::Err: Error + Send + Sync + 'static,

Implementation of AttributeElementExt for Element gives you access to the attribute’s value of an XML element. For example, the id’s value of this XML element <tag id="value" />.

use minidom::Element;
use minidom_ext::AttributeElementExt;

let xml: &'static str = r#"<root id="42" />"#;
let root: Element = xml.parse().unwrap();
let id: u64 = root.try_attribute("id").unwrap();
assert_eq!(42, id);

Implementors§