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.
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();
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
Here's my reference impl Iterator
, I can never remember all the type signatures, I find it helps to note down common impl
s. 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.
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!
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. GitHub - bestia-dev/dodrio_templating: simple templating for dodrio
This is still in working, but I like how it looks.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.