thirdparty: Implement Borrow/Hash/Eq for ThirdPartyIdentifier
This commit is contained in:
parent
afb5ae0102
commit
629b06e1e4
@ -10,6 +10,8 @@ Improvements:
|
|||||||
|
|
||||||
- Add the `InvalidHeaderValue` variant to the `DeserializationError` struct, for
|
- Add the `InvalidHeaderValue` variant to the `DeserializationError` struct, for
|
||||||
cases where we receive a HTTP header with an unexpected value.
|
cases where we receive a HTTP header with an unexpected value.
|
||||||
|
- Implement `Eq`/`Hash`/`PartialEq` for `ThirdPartyIdentifier`, to check whether
|
||||||
|
a `ThirdPartyIdentifier` has already been added by another user.
|
||||||
|
|
||||||
# 0.13.0
|
# 0.13.0
|
||||||
|
|
||||||
|
@ -2,7 +2,10 @@
|
|||||||
//!
|
//!
|
||||||
//! [thirdparty]: https://spec.matrix.org/latest/client-server-api/#third-party-networks
|
//! [thirdparty]: https://spec.matrix.org/latest/client-server-api/#third-party-networks
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::{
|
||||||
|
collections::BTreeMap,
|
||||||
|
hash::{Hash, Hasher},
|
||||||
|
};
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@ -229,7 +232,6 @@ pub enum Medium {
|
|||||||
/// this type using `ThirdPartyIdentifier::Init` / `.into()`.
|
/// this type using `ThirdPartyIdentifier::Init` / `.into()`.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[cfg_attr(test, derive(PartialEq))]
|
|
||||||
pub struct ThirdPartyIdentifier {
|
pub struct ThirdPartyIdentifier {
|
||||||
/// The third party identifier address.
|
/// The third party identifier address.
|
||||||
pub address: String,
|
pub address: String,
|
||||||
@ -244,6 +246,20 @@ pub struct ThirdPartyIdentifier {
|
|||||||
pub added_at: MilliSecondsSinceUnixEpoch,
|
pub added_at: MilliSecondsSinceUnixEpoch,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Eq for ThirdPartyIdentifier {}
|
||||||
|
|
||||||
|
impl Hash for ThirdPartyIdentifier {
|
||||||
|
fn hash<H: Hasher>(&self, hasher: &mut H) {
|
||||||
|
(self.medium.as_str(), &self.address).hash(hasher);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialEq for ThirdPartyIdentifier {
|
||||||
|
fn eq(&self, other: &ThirdPartyIdentifier) -> bool {
|
||||||
|
self.address == other.address && self.medium == other.medium
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Initial set of fields of `ThirdPartyIdentifier`.
|
/// Initial set of fields of `ThirdPartyIdentifier`.
|
||||||
///
|
///
|
||||||
/// This struct will not be updated even if additional fields are added to `ThirdPartyIdentifier`
|
/// This struct will not be updated even if additional fields are added to `ThirdPartyIdentifier`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user