Implement string comparison for identifier types

This commit is contained in:
Jonas Platte 2020-04-16 13:53:17 +02:00
parent 3945f88e10
commit fe70d158e7
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
2 changed files with 48 additions and 0 deletions

View File

@ -80,5 +80,29 @@ macro_rules! common_impls {
crate::deserialize_id(deserializer, $desc)
}
}
impl ::std::cmp::PartialEq<str> for $id {
fn eq(&self, other: &str) -> bool {
self.full_id == other
}
}
impl ::std::cmp::PartialEq<$id> for str {
fn eq(&self, other: &$id) -> bool {
self == other.full_id
}
}
impl ::std::cmp::PartialEq<::std::string::String> for $id {
fn eq(&self, other: &::std::string::String) -> bool {
&self.full_id == other
}
}
impl ::std::cmp::PartialEq<$id> for ::string::String {
fn eq(&self, other: &$id) -> bool {
self == &other.full_id
}
}
};
}

View File

@ -215,6 +215,30 @@ impl TryFrom<String> for RoomVersionId {
}
}
impl PartialEq<str> for RoomVersionId {
fn eq(&self, other: &str) -> bool {
self.as_ref() == other
}
}
impl PartialEq<RoomVersionId> for str {
fn eq(&self, other: &RoomVersionId) -> bool {
self == other.as_ref()
}
}
impl PartialEq<String> for RoomVersionId {
fn eq(&self, other: &String) -> bool {
self.as_ref() == other
}
}
impl PartialEq<RoomVersionId> for String {
fn eq(&self, other: &RoomVersionId) -> bool {
self == other.as_ref()
}
}
#[cfg(test)]
mod tests {
use std::convert::TryFrom;