[][src]Struct reader_for_microxml::ReaderForMicroXml

pub struct ReaderForMicroXml<'a> {
    input: &'a str,
    indices: CharIndices<'a>,
    tag_state: TagState,
    last_char: PosChar,
    start_of_text_node_before_whitespace: usize,
}

struct Reader for MicroXml - the Class
Rust has Structs + Traits, but for me it is just like Class/Object.
Just without inheritance.
All the fields are internal and not public.
The only way to interact is through methods.

Fields

input: &'a str

reference to the xml string (no allocation)

indices: CharIndices<'a>

Iterator CharIndices over the input string

tag_state: TagState

I need to know the TagState for programming as a state machine

last_char: PosChar

the last read character from the indices iterator

start_of_text_node_before_whitespace: usize

for significant whitespace (in TextNode beginning)

Implementations

impl<'a> ReaderForMicroXml<'a>[src]

pub fn new(input: &str) -> ReaderForMicroXml<'_>

Notable traits for ReaderForMicroXml<'a>

impl<'a> Iterator for ReaderForMicroXml<'a> type Item = Result<Token<'a>, &'static str>;
[src]

Constructor. String is immutably borrowed here. No allocation.

fn read_token_internal(&mut self) -> Option<Result<Token<'a>, &'static str>>[src]

Reads the next token (internal).
The internal function can understand when the Eof is in a correct position
and stops the propagation of Option None.

fn read_element_name(&mut self) -> Option<Result<Token<'a>, &'static str>>[src]

Reads the element name
Propagation of Option None if is Eof

fn read_attribute(&mut self) -> Option<Result<Token<'a>, &'static str>>[src]

Reads the attribute name and value.
Return Option None if Eof.

fn read_end_element(&mut self) -> Option<Result<Token<'a>, &'static str>>[src]

reads end element

fn read_text_node(&mut self) -> Option<Result<Token<'a>, &'static str>>[src]

Reads text node
I don't do any encoding/decoding here, because I need it "as is" for html templating.
I preserve all the "significant" whitespaces because I will use this for templating.
And because there is no hard standard for trailing spaces in xml text node.
If reached Eof propagates Option None.

fn read_comment(&mut self) -> Option<Result<Token<'a>, &'static str>>[src]

Comments are not data for MicroXml standard,
But I need them as data for my templating project.
The Option is returned only because of Option None propagation because of Eof.

fn move_next_char(&mut self) -> Option<()>[src]

Moves the iterator and stores the last_char.
Iterator next() of CharIndices is consuming the char.
There is no way back to the same char.
But often I need to get again the same character of the last operation.
I tried with peekable.peek(), but it gives a reference and this was a problem.
So now I have 2 separate methods: move_next_char() and get_last_char().
I store the last_char for repeated use.
Anytime it can reach the End of File (Eof),
then it propagates the Option None to the caller with the ? syntax.
Only the caller knows if the Eof here is ok or it is an unexpected error.
The usize inside the Option is only a dummy,
only because I need to propagate the Option None because of Eof

fn move_over_whitespaces(&mut self) -> Option<()>[src]

Skips all whitespaces if there is any
and returns the last_char when it is not whitespace.
saves the whitespace beginning position, because the caller must know if the whitespaces are insignificant. For example TextNode.
If found Eof, propagates Option None.

Trait Implementations

impl<'a> Iterator for ReaderForMicroXml<'a>[src]

type Item = Result<Token<'a>, &'static str>

The type of the elements being iterated over.

fn next(&mut self) -> Option<Result<Token<'a>, &'static str>>[src]

Reads the next token: StartElement, Attribute, Text, EndElement

Auto Trait Implementations

impl<'a> Send for ReaderForMicroXml<'a>

impl<'a> Sync for ReaderForMicroXml<'a>

impl<'a> Unpin for ReaderForMicroXml<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.