Struct svg_simple_parser::Element[][src]

pub struct Element<'a> {
    pub ele_type: &'a str,
    pub attributes: Rc<RefCell<HashMap<String, &'a str>>>,
    pub children: RefCell<Vec<Rc<RefCell<Element<'a>>>>>,
}
Expand description

AST struct

ele_type the type of the element

attributes the attributes in the element

children the children in the element

Fields

ele_type: &'a strattributes: Rc<RefCell<HashMap<String, &'a str>>>children: RefCell<Vec<Rc<RefCell<Element<'a>>>>>

Implementations

new a element without children

Example
use std::collections::HashMap;
use svg_simple_parser::Element;

Element::new(("rect",HashMap::from([("width".to_owned(), "100"),("height".to_owned(), "100")])));

new a element with children

Example
use std::collections::HashMap;
use svg_simple_parser::Element;

let child = Element::new(("rect",HashMap::from([("width".to_owned(), "100"),("height".to_owned(), "100")])));
Element::new_width_children(("rect",HashMap::from([("width".to_owned(), "100"),("height".to_owned(), "100")]),vec![child]));

add a element to the children of the element.

Example
use std::collections::HashMap;
use svg_simple_parser::Element;

let parent = Element::new(("rect",HashMap::from([("width".to_owned(), "100"),("height".to_owned(), "100")])));
let child = Element::new(("rect",HashMap::from([("width".to_owned(), "100"),("height".to_owned(), "100")])));
Element::add_child(parent.clone(),child.clone());
assert_eq!(parent.borrow().children.borrow().get(0),Some(&child));

add a list of element to the children of the element.

Example
use std::collections::HashMap;
use svg_simple_parser::Element;

let parent = Element::new(("rect",HashMap::from([("width".to_owned(), "100"),("height".to_owned(), "100")])));
let child = Element::new(("rect",HashMap::from([("width".to_owned(), "100"),("height".to_owned(), "100")])));
Element::add_children(parent.clone(),vec![child.clone()].as_mut());
assert_eq!(parent.borrow().children.borrow().get(0),Some(&child));

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.