add getters for node and domain on Jid
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
36b51171ce
commit
750562cd96
1 changed files with 32 additions and 0 deletions
32
src/lib.rs
32
src/lib.rs
|
@ -92,6 +92,22 @@ impl From<FullJid> for Jid {
|
|||
}
|
||||
}
|
||||
|
||||
impl Jid {
|
||||
/// The node part of the Jabber ID, if it exists, else None.
|
||||
pub fn node(self) -> Option<String> {
|
||||
match self {
|
||||
Jid::Bare(BareJid { node, .. }) | Jid::Full(FullJid { node, .. }) => node,
|
||||
}
|
||||
}
|
||||
|
||||
/// The domain of the Jabber ID.
|
||||
pub fn domain(self) -> String {
|
||||
match self {
|
||||
Jid::Bare(BareJid { domain, .. }) | Jid::Full(FullJid { domain, .. }) => domain,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A struct representing a full Jabber ID.
|
||||
///
|
||||
/// A full Jabber ID is composed of 3 components, of which one is optional:
|
||||
|
@ -639,6 +655,22 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn node_from_jid() {
|
||||
assert_eq!(
|
||||
Jid::Full(FullJid::new("a", "b.c", "d")).node(),
|
||||
Some(String::from("a")),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn domain_from_jid() {
|
||||
assert_eq!(
|
||||
Jid::Bare(BareJid::new("a", "b.c")).domain(),
|
||||
String::from("b.c"),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialise() {
|
||||
assert_eq!(
|
||||
|
|
Loading…
Reference in a new issue