mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
jid: skip at
and slash
in comparison operators
They only contain cached information and thus don't need to be included in comparison and identity operators. Fixes #123.
This commit is contained in:
parent
c895cb1009
commit
c08946aa7c
1 changed files with 27 additions and 1 deletions
|
@ -32,7 +32,9 @@
|
||||||
|
|
||||||
use core::num::NonZeroU16;
|
use core::num::NonZeroU16;
|
||||||
use std::borrow::{Borrow, Cow};
|
use std::borrow::{Borrow, Cow};
|
||||||
|
use std::cmp::Ordering;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::hash::{Hash, Hasher};
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
@ -78,13 +80,37 @@ fn length_check(len: usize, error_empty: Error, error_too_long: Error) -> Result
|
||||||
///
|
///
|
||||||
/// This dynamic type on the other hand can be used in contexts where it is
|
/// This dynamic type on the other hand can be used in contexts where it is
|
||||||
/// not known, at compile-time, whether a JID is full or bare.
|
/// not known, at compile-time, whether a JID is full or bare.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, Eq)]
|
||||||
pub struct Jid {
|
pub struct Jid {
|
||||||
normalized: String,
|
normalized: String,
|
||||||
at: Option<NonZeroU16>,
|
at: Option<NonZeroU16>,
|
||||||
slash: Option<NonZeroU16>,
|
slash: Option<NonZeroU16>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PartialEq for Jid {
|
||||||
|
fn eq(&self, other: &Jid) -> bool {
|
||||||
|
self.normalized == other.normalized
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialOrd for Jid {
|
||||||
|
fn partial_cmp(&self, other: &Jid) -> Option<Ordering> {
|
||||||
|
self.normalized.partial_cmp(&other.normalized)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Ord for Jid {
|
||||||
|
fn cmp(&self, other: &Jid) -> Ordering {
|
||||||
|
self.normalized.cmp(&other.normalized)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Hash for Jid {
|
||||||
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
|
self.normalized.hash(state)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl FromStr for Jid {
|
impl FromStr for Jid {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue