pub struct Element { /* private fields */ }
Expand description
General content of an event (aka node)
Element is a wrapper over the bytes representing the node:
E.g. given a node <name att1="a", att2="b">
, the corresponding Event
will be
Event::Start(Element {
buf: b"name att1=\"a\", att2=\"b\"",
start: 0,
end: b"name att1=\"a\", att2=\"b\"".len(),
name_end: b"name".len()
})
For performance reasons, most of the time, no character searches but
b'<'
and b'>'
are performed:
- no attribute parsing: use lazy
Attributes
iterator only when needed - no namespace awareness as it requires parsing all
Start
element attributes - no utf8 conversion: prefer searching statically binary comparisons
then use the
as_str
orinto_string
methods
Implementations§
source§impl Element
impl Element
sourcepub fn new<A>(name: A) -> Element
pub fn new<A>(name: A) -> Element
Creates a new Element from the given name. name is a reference that can be converted to a byte slice, such as &u8 or &str
sourcepub fn with_attributes<K, V, I>(self, attributes: I) -> Self
pub fn with_attributes<K, V, I>(self, attributes: I) -> Self
Consumes self and adds attributes to this element from an iterator over (key, value) tuples. Key and value can be anything that implements the AsRef<u8> trait, like byte slices and strings.
sourcepub fn unescaped_content(&self) -> ResultPos<Cow<'_, [u8]>>
pub fn unescaped_content(&self) -> ResultPos<Cow<'_, [u8]>>
gets escaped content
Searches for ‘&’ into content and try to escape the coded character if possible returns Malformed error with index within element if ‘&’ is not followed by ‘;’
sourcepub fn attributes(&self) -> Attributes<'_> ⓘ
pub fn attributes(&self) -> Attributes<'_> ⓘ
gets attributes iterator
sourcepub fn unescaped_attributes(&self) -> UnescapedAttributes<'_> ⓘ
pub fn unescaped_attributes(&self) -> UnescapedAttributes<'_> ⓘ
gets attributes iterator whose attribute values are unescaped (‘&…;’ replaced by their corresponding character)
sourcepub fn extend_attributes<K, V, I>(&mut self, attributes: I) -> &mut Element
pub fn extend_attributes<K, V, I>(&mut self, attributes: I) -> &mut Element
extend the attributes of this element from an iterator over (key, value) tuples. Key and value can be anything that implements the AsRef<u8> trait, like byte slices and strings.
sourcepub fn into_string(self) -> Result<String>
pub fn into_string(self) -> Result<String>
consumes entire self (including eventual attributes!) and returns String
useful when we need to get Text event value (which don’t have attributes)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Element
impl RefUnwindSafe for Element
impl Send for Element
impl Sync for Element
impl Unpin for Element
impl UnwindSafe for Element
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)