Add PartialOrd and Ord implementations for RoomVersionId

This commit is contained in:
Jonas Platte 2020-06-01 01:19:03 +02:00
parent f6f0b58a1c
commit 1093c2f84d
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
2 changed files with 15 additions and 1 deletions

View File

@ -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

View File

@ -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<Ordering> {
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<S>(&self, serializer: S) -> Result<S::Ok, S::Error>