mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
Implement as_str
on all Jid types
This is useful for printing with quotes without copying any data.
This commit is contained in:
parent
9608b59f60
commit
2c701038cd
3 changed files with 23 additions and 0 deletions
|
@ -20,6 +20,7 @@ Version xxx, release xxx:
|
||||||
`impl From<DomainPart> for BareJid` and
|
`impl From<DomainPart> for BareJid` and
|
||||||
`impl From<DomainPart> for Jid`, both of which are (unlike
|
`impl From<DomainPart> for Jid`, both of which are (unlike
|
||||||
`::from_parts`) copy-free.
|
`::from_parts`) copy-free.
|
||||||
|
- `as_str` methods have been added on all Jid types.
|
||||||
|
|
||||||
Version 0.10.0, release 2023-08-17:
|
Version 0.10.0, release 2023-08-17:
|
||||||
* Breaking
|
* Breaking
|
||||||
|
|
|
@ -141,6 +141,11 @@ impl InnerJid {
|
||||||
ResourceRef::from_str_unchecked(&self.normalized[slash + 1..])
|
ResourceRef::from_str_unchecked(&self.normalized[slash + 1..])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub(crate) fn as_str(&self) -> &str {
|
||||||
|
self.normalized.as_str()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for InnerJid {
|
impl FromStr for InnerJid {
|
||||||
|
|
|
@ -196,6 +196,13 @@ impl Jid {
|
||||||
pub fn is_bare(&self) -> bool {
|
pub fn is_bare(&self) -> bool {
|
||||||
!self.is_full()
|
!self.is_full()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return a reference to the canonical string representation of the JID.
|
||||||
|
pub fn as_str(&self) -> &str {
|
||||||
|
match self {
|
||||||
|
Jid::Bare(BareJid { inner }) | Jid::Full(FullJid { inner }) => inner.as_str(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<Jid> for FullJid {
|
impl TryFrom<Jid> for FullJid {
|
||||||
|
@ -482,6 +489,11 @@ impl FullJid {
|
||||||
self.inner.slash = None;
|
self.inner.slash = None;
|
||||||
BareJid { inner: self.inner }
|
BareJid { inner: self.inner }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return a reference to the canonical string representation of the JID.
|
||||||
|
pub fn as_str(&self) -> &str {
|
||||||
|
self.inner.as_str()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for BareJid {
|
impl FromStr for BareJid {
|
||||||
|
@ -608,6 +620,11 @@ impl BareJid {
|
||||||
let resource = ResourcePart::new(resource)?;
|
let resource = ResourcePart::new(resource)?;
|
||||||
Ok(self.with_resource(&resource))
|
Ok(self.with_resource(&resource))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return a reference to the canonical string representation of the JID.
|
||||||
|
pub fn as_str(&self) -> &str {
|
||||||
|
self.inner.as_str()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "minidom")]
|
#[cfg(feature = "minidom")]
|
||||||
|
|
Loading…
Reference in a new issue