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 str
attributes: 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
Auto Trait Implementations
impl<'a> !RefUnwindSafe for Element<'a>
impl<'a> !UnwindSafe for Element<'a>
Blanket Implementations
Mutably borrows from an owned value. Read more