diff --git a/crates/ruma-client-api/CHANGELOG.md b/crates/ruma-client-api/CHANGELOG.md index a6166f92..50241b44 100644 --- a/crates/ruma-client-api/CHANGELOG.md +++ b/crates/ruma-client-api/CHANGELOG.md @@ -6,6 +6,7 @@ Breaking changes: * Use `sync::sync_events::DeviceLists` instead * `fully_read` field in `read_marker::set_read_marker` is no longer required * Remove the `fully_read` argument from `read_marker::set_read_marker::Request::new` +* Move `message::get_message_events::v3::Direction` to the root of the crate Improvements: diff --git a/crates/ruma-client-api/src/lib.rs b/crates/ruma-client-api/src/lib.rs index 2f2be9c8..72678dac 100644 --- a/crates/ruma-client-api/src/lib.rs +++ b/crates/ruma-client-api/src/lib.rs @@ -51,6 +51,7 @@ pub mod voip; use std::fmt; pub use error::Error; +use serde::{Deserialize, Serialize}; // Wrapper around `Box` that cannot be used in a meaningful way outside of // this crate. Used for string enums because their `_Custom` variant can't be @@ -64,3 +65,17 @@ impl fmt::Debug for PrivOwnedStr { self.0.fmt(f) } } + +/// The direction to return events from. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Deserialize, Serialize)] +#[allow(clippy::exhaustive_enums)] +pub enum Direction { + /// Return events backwards in time from the requested `from` token. + #[default] + #[serde(rename = "b")] + Backward, + + /// Return events forwards in time from the requested `from` token. + #[serde(rename = "f")] + Forward, +} diff --git a/crates/ruma-client-api/src/message/get_message_events.rs b/crates/ruma-client-api/src/message/get_message_events.rs index a513c891..24d6016c 100644 --- a/crates/ruma-client-api/src/message/get_message_events.rs +++ b/crates/ruma-client-api/src/message/get_message_events.rs @@ -12,9 +12,11 @@ pub mod v3 { serde::Raw, RoomId, }; - use serde::{Deserialize, Serialize}; - use crate::filter::{IncomingRoomEventFilter, RoomEventFilter}; + use crate::{ + filter::{IncomingRoomEventFilter, RoomEventFilter}, + Direction, + }; ruma_api! { metadata: { @@ -169,19 +171,6 @@ pub mod v3 { *val == default_limit() } - /// The direction to return events from. - #[derive(Clone, Debug, Deserialize, Serialize)] - #[allow(clippy::exhaustive_enums)] - pub enum Direction { - /// Return events backwards in time from the requested `from` token. - #[serde(rename = "b")] - Backward, - - /// Return events forwards in time from the requested `from` token. - #[serde(rename = "f")] - Forward, - } - #[cfg(all(test, feature = "client"))] mod tests { use js_int::uint; @@ -190,8 +179,11 @@ pub mod v3 { room_id, }; - use super::{Direction, Request}; - use crate::filter::{LazyLoadOptions, RoomEventFilter}; + use super::Request; + use crate::{ + filter::{LazyLoadOptions, RoomEventFilter}, + Direction, + }; #[test] fn serialize_some_room_event_filter() {