pub struct Element<'a> {
pub ele_type: &'a str,
pub attributes: RefCell<HashMap<String, &'a str>>,
pub parent: RefCell<Weak<Element<'a>>>,
pub children: RefCell<Vec<Rc<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: RefCell<HashMap<String, &'a str>>
§parent: RefCell<Weak<Element<'a>>>
§children: RefCell<Vec<Rc<Element<'a>>>>
Implementations§
Source§impl<'a> Element<'a>
impl<'a> Element<'a>
Sourcepub fn new(
(ele_type, attributes): (&'a str, HashMap<String, &'a str>),
) -> Rc<Self>
pub fn new( (ele_type, attributes): (&'a str, HashMap<String, &'a str>), ) -> Rc<Self>
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")])));
Sourcepub fn new_width_children(
(ele_type, attributes, children): (&'a str, HashMap<String, &'a str>, Vec<Rc<Element<'a>>>),
) -> Rc<Self>
pub fn new_width_children( (ele_type, attributes, children): (&'a str, HashMap<String, &'a str>, Vec<Rc<Element<'a>>>), ) -> Rc<Self>
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]));
Sourcepub fn add_child(self: &Rc<Element<'a>>, new_item: Rc<Element<'a>>)
pub fn add_child(self: &Rc<Element<'a>>, new_item: Rc<Element<'a>>)
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));
Sourcepub fn add_children(self: &Rc<Element<'a>>, new_items: Vec<Rc<Element<'a>>>)
pub fn add_children(self: &Rc<Element<'a>>, new_items: Vec<Rc<Element<'a>>>)
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> !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