api: Rework VersionHistory path accessors
* Return iterators * Rename all_unstable_paths to unstable_paths * Rename all_versioned_stable_paths to stable_paths
This commit is contained in:
parent
94990f60f2
commit
848ca9b225
@ -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<Item = &'static str> {
|
||||
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<Item = &'static str> {
|
||||
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<Item = (MatrixVersion, &'static str)> {
|
||||
self.stable_paths.iter().map(|(version, data)| (*version, *data))
|
||||
}
|
||||
|
||||
/// The path that should be used to query the endpoint, given a series of versions.
|
||||
|
@ -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::<Vec<_>>(),
|
||||
&["/_matrix/some/msc1234/endpoint/:baz"],
|
||||
);
|
||||
assert_eq!(
|
||||
METADATA.history.stable_paths().collect::<Vec<_>>(),
|
||||
&[
|
||||
(MatrixVersion::V1_0, "/_matrix/some/r0/endpoint/:baz"),
|
||||
(MatrixVersion::V1_1, "/_matrix/some/v3/endpoint/:baz")
|
||||
|
Loading…
x
Reference in New Issue
Block a user