diff --git a/crates/ruma-common/src/api/metadata.rs b/crates/ruma-common/src/api/metadata.rs index e56daaf9..9d4ba5f0 100644 --- a/crates/ruma-common/src/api/metadata.rs +++ b/crates/ruma-common/src/api/metadata.rs @@ -391,20 +391,18 @@ impl VersionHistory { } /// Returns all path variants in canon form, for use in server routers. - pub fn all_paths(&self) -> Vec<&'static str> { - let unstable = self.unstable_paths.iter().copied(); - let stable = self.stable_paths.iter().map(|(_, y)| *y); - unstable.chain(stable).collect() + pub fn all_paths(&self) -> impl Iterator { + self.unstable_paths().chain(self.stable_paths().map(|(_, path)| path)) } /// Returns all unstable path variants in canon form. - pub fn all_unstable_paths(&self) -> Vec<&'static str> { - self.unstable_paths.to_owned() + pub fn unstable_paths(&self) -> impl Iterator { + self.unstable_paths.iter().copied() } /// Returns all stable path variants in canon form, with corresponding Matrix version. - pub fn all_versioned_stable_paths(&self) -> Vec<(MatrixVersion, &'static str)> { - self.stable_paths.iter().map(|(version, data)| (*version, *data)).collect() + pub fn stable_paths(&self) -> impl Iterator { + self.stable_paths.iter().map(|(version, data)| (*version, *data)) } /// The path that should be used to query the endpoint, given a series of versions. diff --git a/crates/ruma-common/tests/api/ui/01-api-sanity-check.rs b/crates/ruma-common/tests/api/ui/01-api-sanity-check.rs index f221750d..366c553b 100644 --- a/crates/ruma-common/tests/api/ui/01-api-sanity-check.rs +++ b/crates/ruma-common/tests/api/ui/01-api-sanity-check.rs @@ -61,9 +61,12 @@ ruma_api! { fn main() { use ruma_common::api::MatrixVersion; - assert_eq!(METADATA.history.all_unstable_paths(), &["/_matrix/some/msc1234/endpoint/:baz"],); assert_eq!( - METADATA.history.all_versioned_stable_paths(), + METADATA.history.unstable_paths().collect::>(), + &["/_matrix/some/msc1234/endpoint/:baz"], + ); + assert_eq!( + METADATA.history.stable_paths().collect::>(), &[ (MatrixVersion::V1_0, "/_matrix/some/r0/endpoint/:baz"), (MatrixVersion::V1_1, "/_matrix/some/v3/endpoint/:baz")