mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
Merge branch 'master' into 'master'
Simplify and prettify Display and Debug implementations See merge request !2
This commit is contained in:
commit
940d49914e
1 changed files with 9 additions and 9 deletions
18
src/lib.rs
18
src/lib.rs
|
@ -24,7 +24,7 @@ pub enum JidParseError {
|
||||||
/// - A node/name, `node`, which is the optional part before the @.
|
/// - A node/name, `node`, which is the optional part before the @.
|
||||||
/// - A domain, `domain`, which is the mandatory part after the @ but before the /.
|
/// - A domain, `domain`, which is the mandatory part after the @ but before the /.
|
||||||
/// - A resource, `resource`, which is the optional part after the /.
|
/// - A resource, `resource`, which is the optional part after the /.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
pub struct Jid {
|
pub struct Jid {
|
||||||
/// The node part of the Jabber ID, if it exists, else None.
|
/// The node part of the Jabber ID, if it exists, else None.
|
||||||
pub node: Option<String>,
|
pub node: Option<String>,
|
||||||
|
@ -50,16 +50,16 @@ impl From<Jid> for String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for Jid {
|
||||||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
|
write!(fmt, "JID({})", self)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Display for Jid {
|
impl fmt::Display for Jid {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
// TODO: may need escaping
|
fmt.write_str(String::from(self.clone()).as_ref())?;
|
||||||
if let Some(ref node) = self.node {
|
|
||||||
write!(fmt, "{}@", node)?;
|
|
||||||
}
|
|
||||||
write!(fmt, "{}", self.domain)?;
|
|
||||||
if let Some(ref resource) = self.resource {
|
|
||||||
write!(fmt, "/{}", resource)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue