xmpp_parsers/
stream_limits.rs1use xso::{AsXml, FromXml};
8
9use crate::ns;
10use core::num::NonZeroU32;
11
12#[derive(FromXml, AsXml, Debug, Clone, PartialEq)]
14#[xml(namespace = ns::STREAM_LIMITS, name = "limits")]
15pub struct Limits {
16 #[xml(extract(default, name = "max-bytes", fields(text(type_ = NonZeroU32))))]
19 pub max_bytes: Option<NonZeroU32>,
20
21 #[xml(extract(default, name = "idle-seconds", fields(text(type_ = NonZeroU32))))]
24 pub idle_seconds: Option<NonZeroU32>,
25}
26
27#[cfg(test)]
28mod tests {
29 use super::*;
30 use minidom::Element;
31
32 #[test]
33 fn test_size() {
34 assert_size!(Limits, 8);
35 }
36
37 #[test]
38 fn test_simple() {
39 let elem: Element =
40 "<limits xmlns='urn:xmpp:stream-limits:0'><max-bytes>262144</max-bytes></limits>"
41 .parse()
42 .unwrap();
43 let limits = Limits::try_from(elem).unwrap();
44 assert_eq!(limits.max_bytes.unwrap(), NonZeroU32::new(262144).unwrap());
45 assert!(limits.idle_seconds.is_none());
46 }
47}