forked from lavina/lavina
1
0
Fork 0
lavina/src/util/xml.rs

32 lines
588 B
Rust
Raw Normal View History

2023-03-07 13:56:31 +00:00
use quick_xml::events::Event;
2023-03-08 18:56:53 +00:00
use crate::prelude::Result;
pub trait FromXml: Sized {
type P: Parser<Output = Result<Self>>;
fn parse() -> Self::P;
}
2023-03-07 13:56:31 +00:00
pub trait Parser: Sized {
type Output;
fn consume<'a>(self: Self, event: &Event<'a>) -> Continuation<Self, Self::Output>;
}
pub enum Continuation<Parser, Res> {
Final(Res),
Continue(Parser),
}
macro_rules! fail_fast {
($errorable: expr) => {
match $errorable {
Ok(i) => i,
Err(e) => return Continuation::Final(Err(e.into())),
2023-03-07 13:56:31 +00:00
}
};
}
pub(crate) use fail_fast;