Announce reader for microxml 1.0.4

MicroXML is a subset of XML. It is dramatically simpler.
In most cases this is all we want and need in real life.
All the complexity of the full Xml standard just vanishes.
I just love it.
https://crates.io/crates/reader_for_microxml
This crate is a simple reader for small microXml strings/files.
I would much appreciate comments.

Can you implement Iterator for ReaderForMicroXml? That would make it a bit easier to use.

1 Like

I'm curious how you would handle errors in an iterator here:
My first call is to return
Option<Result<String, ParseErr>>
so Some(Err("malformed XML")) if we got an error and None to finish.

I'd definitely recommend using a Result in that scenario. The nice thing about it is that you can use some collect magic to do more complex error handling. For example, you can do:

let output: Result<Vec<String>, ParseErr> = iterator.collect();

This will either return the first error encountered, or return a Vec of all the items of the iterator.

2 Likes

I think we agree, the iterator will use Item = Result but when impl Iterator you have to return Option<Item>. I definitely didn't make that very clear though, thanks for expanding on the features Results and Iterators have :slight_smile:

Here's my reference impl Iterator, I can never remember all the type signatures, I find it helps to note down common impls. It's almost certainly lifted from the book or somewhere!

impl Iterator for Counter {
    type Item = usize;

    fn next(&mut self) -> Option<Self::Item> {
        ...
        Some(usize)
        None // stop iterating
    }
}

Sorry for hijacking had never seen microXML before and it seems like a great idea. Good to have it in the rust ecosystem.

1 Like

I wasn't aware that .collect() could collect into a Result. I always thought that the Iterator trait was Result-deficient.
So thanks for the tip!

2 Likes

Thank you. I appreciate your suggestions. I will get to it as soon as I find some time. I am using this for a simple html templating for dodrio virtual dom. https://github.com/LucianoBestia/dodrio_templating
This is still in working, but I like how it looks.