diff --git a/CHANGELOG.md b/CHANGELOG.md index dab12c02..1f7f35b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Improvements: * Update the internal representation of identifiers to be more compact * Add `RoomVersionId::version_6` and `RoomVersionId::is_version_6` +* Add `PartialOrd` and `Ord` implementations for `RoomVersionId` # 0.16.1 diff --git a/src/room_version_id.rs b/src/room_version_id.rs index b5d1f58a..bcffda3d 100644 --- a/src/room_version_id.rs +++ b/src/room_version_id.rs @@ -1,6 +1,7 @@ //! Matrix room version identifiers. use std::{ + cmp::Ordering, convert::TryFrom, fmt::{self, Display, Formatter}, }; @@ -23,7 +24,7 @@ const MAX_CODE_POINTS: usize = 32; /// # use ruma_identifiers::RoomVersionId; /// assert_eq!(RoomVersionId::try_from("1").unwrap().as_ref(), "1"); /// ``` -#[derive(Clone, Debug, Eq, Hash, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct RoomVersionId(InnerRoomVersionId); /// Possibile values for room version, distinguishing between official Matrix versions and custom @@ -166,6 +167,18 @@ impl Display for RoomVersionId { } } +impl PartialOrd for RoomVersionId { + fn partial_cmp(&self, other: &RoomVersionId) -> Option { + self.as_ref().partial_cmp(other.as_ref()) + } +} + +impl Ord for RoomVersionId { + fn cmp(&self, other: &Self) -> Ordering { + self.as_ref().cmp(other.as_ref()) + } +} + #[cfg(feature = "serde")] impl Serialize for RoomVersionId { fn serialize(&self, serializer: S) -> Result