xmpp-rs/parsers/src/util
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Jonas Schäfer 2f7d5edb8a Make TryFrom<Element> chainable
This allows constructs like:

```rust
let residual = match Iq::try_from(stanza) {
  Ok(iq) => return handle_iq(..),
  Err(Error::TypeMismatch(_, _, v)) => v,
  Err(other) => return handle_parse_error(..),
};
let residual = match Message::try_from(stanza) {
  ..
};
let residual = ..
log::warn!("unhandled object: {:?}", residual);
```

The interesting part of this is that this could be used in a loop over a
Vec<Box<dyn FnMut(Element) -> ControlFlow<SomeResult, Element>>, i.e. in
a parsing loop for a generic XML/XMPP stream.

The advantage is that the stanza.is() check runs only once (in
check_self!) and doesn't need to be duplicated outside, and it reduces
the use of magic strings.
2024-03-03 14:50:29 +00:00
..
error.rs Make TryFrom<Element> chainable 2024-03-03 14:50:29 +00:00
macros.rs Make TryFrom<Element> chainable 2024-03-03 14:50:29 +00:00
mod.rs Refactored the "helpers" so that they use a common Codec trait; this makes them composable as well. 2024-01-10 19:49:53 +00:00
text_node_codecs.rs Refactored the "helpers" so that they use a common Codec trait; this makes them composable as well. 2024-01-10 19:49:53 +00:00