From 3107259337861bc585db1315c68ca5cffc826fab Mon Sep 17 00:00:00 2001 From: Link Mauve Date: Sun, 25 Jan 2026 18:32:53 +0100 Subject: [PATCH] xmpp-parsers: Use #[xml(extract)] for the two values This simplifies the API, and avoids extra newtypes. --- parsers/ChangeLog | 1 + parsers/src/stream_limits.rs | 37 +++++------------------------------- 2 files changed, 6 insertions(+), 32 deletions(-) diff --git a/parsers/ChangeLog b/parsers/ChangeLog index 4b4353ce..64857e29 100644 --- a/parsers/ChangeLog +++ b/parsers/ChangeLog @@ -13,6 +13,7 @@ XXXX-YY-ZZ RELEASER SASL mechanisms in a Vec in StreamFeatures. - bind::BindFeature::required is now a bool, thanks to xso’s flag. - jingle_rtp::Description::rtcp_mux is now a bool flag too. + - stream_limits::Limits now extract directly to NonZeroU32. * Improvements: - Make Priority’s inner i8 pub, which had been broken since the conversion to xso. (!632) diff --git a/parsers/src/stream_limits.rs b/parsers/src/stream_limits.rs index aa6ed4b6..786d0ed6 100644 --- a/parsers/src/stream_limits.rs +++ b/parsers/src/stream_limits.rs @@ -15,35 +15,13 @@ use core::num::NonZeroU32; pub struct Limits { /// Maximum size of any first-level stream elements (including stanzas), in bytes the /// announcing entity is willing to accept. - // TODO: Replace that with a direct u32 once xso supports that. - #[xml(child(default))] - pub max_bytes: Option, + #[xml(extract(default, name = "max-bytes", fields(text(type_ = NonZeroU32))))] + pub max_bytes: Option, /// Number of seconds without any traffic from the initiating entity after which the server may /// consider the stream idle, and either perform liveness checks or terminate the stream. - // TODO: Replace that with a direct u32 once xso supports that. - #[xml(child(default))] - pub idle_seconds: Option, -} - -/// Maximum size of any first-level stream elements (including stanzas), in bytes the -/// announcing entity is willing to accept. -#[derive(FromXml, AsXml, Debug, Clone, PartialEq)] -#[xml(namespace = ns::STREAM_LIMITS, name = "max-bytes")] -pub struct MaxBytes { - /// The number of bytes. - #[xml(text)] - pub value: NonZeroU32, -} - -/// Number of seconds without any traffic from the initiating entity after which the server may -/// consider the stream idle, and either perform liveness checks or terminate the stream. -#[derive(FromXml, AsXml, Debug, Clone, PartialEq)] -#[xml(namespace = ns::STREAM_LIMITS, name = "idle-seconds")] -pub struct IdleSeconds { - /// The number of seconds. - #[xml(text)] - pub value: NonZeroU32, + #[xml(extract(default, name = "idle-seconds", fields(text(type_ = NonZeroU32))))] + pub idle_seconds: Option, } #[cfg(test)] @@ -54,8 +32,6 @@ mod tests { #[test] fn test_size() { assert_size!(Limits, 8); - assert_size!(MaxBytes, 4); - assert_size!(IdleSeconds, 4); } #[test] @@ -65,10 +41,7 @@ mod tests { .parse() .unwrap(); let limits = Limits::try_from(elem).unwrap(); - assert_eq!( - limits.max_bytes.unwrap().value, - NonZeroU32::new(262144).unwrap() - ); + assert_eq!(limits.max_bytes.unwrap(), NonZeroU32::new(262144).unwrap()); assert!(limits.idle_seconds.is_none()); } }