pub struct Element<'a> {
pub name: &'a str,
pub attributes: HashMap<&'a str, Attribute<'a>>,
pub contents: Vec<Content<'a>>,
pub position: Position<'a>,
}Fields§
§name: &'a str§attributes: HashMap<&'a str, Attribute<'a>>§contents: Vec<Content<'a>>§position: Position<'a>Implementations§
Source§impl<'a> Element<'a>
impl<'a> Element<'a>
Sourcepub fn children<'b, 'c, T: FromElement<'a, 'b>>(
&'b self,
name: &'c str,
) -> impl Iterator<Item = Result<'a, T>> + use<'a, 'b, 'c, T>
pub fn children<'b, 'c, T: FromElement<'a, 'b>>( &'b self, name: &'c str, ) -> impl Iterator<Item = Result<'a, T>> + use<'a, 'b, 'c, T>
Examples found in repository?
examples/network.rs (line 30)
28 fn from_element(element: &'b Element<'a>) -> Result<'a, Self> {
29 Ok(Config {
30 servers: element.children("server").collect::<Result<_>>()?,
31 })
32 }
33}
34
35/// This represents a theoretical server that we want to
36/// list information about in our config.
37#[derive(Debug)]
38struct Server {
39 name: String,
40 ip: Ipv4Addr,
41 aliases: Vec<Alias>,
42}
43
44impl<'a, 'b> FromElement<'a, 'b> for Server {
45 fn from_element(element: &'b Element<'a>) -> Result<'a, Self> {
46 Ok(Server {
47 name: element.attribute("name")?,
48 ip: element.attribute::<IP>("ip")?.0,
49 aliases: element.children("alias").collect::<Result<Vec<_>>>()?,
50 })
51 }pub fn child<'b, 'c, T: FromElement<'a, 'b>>( &'b self, name: &'c str, ) -> Result<'a, T>
pub fn optional_child<'b, 'c, T: FromElement<'a, 'b>>( &'b self, name: &'c str, ) -> Result<'a, Option<T>>
Trait Implementations§
Source§impl<'a, 'b> FromElement<'a, 'b> for &'b Element<'a>
impl<'a, 'b> FromElement<'a, 'b> for &'b Element<'a>
fn from_element(element: &'b Element<'a>) -> Result<'a, Self>
Auto Trait Implementations§
impl<'a> Freeze for Element<'a>
impl<'a> RefUnwindSafe for Element<'a>
impl<'a> Send for Element<'a>
impl<'a> Sync for Element<'a>
impl<'a> Unpin for Element<'a>
impl<'a> UnwindSafe for Element<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more