pub trait AsXmlText {
    // Required method
    fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>;
    // Provided method
    fn as_optional_xml_text(&self) -> Result<Option<Cow<'_, str>>, Error> { ... }
}Expand description
Trait to convert a value to an XML text string.
Implementing this trait for a type allows it to be used both for XML
character data within elements and for XML attributes. For XML attributes,
the behaviour is defined by AsXmlText::as_optional_xml_text, while
XML element text content uses AsXmlText::as_xml_text. Implementing
AsXmlText automatically provides an implementation of
AsOptionalXmlText.
If your type should only be used in XML attributes and has no correct
serialisation in XML text, you should only implement
AsOptionalXmlText and omit the AsXmlText implementation.
Important: See the text module’s documentation
for notes regarding implementations for types from third-party crates.
Required Methods§
Provided Methods§
Sourcefn as_optional_xml_text(&self) -> Result<Option<Cow<'_, str>>, Error>
 
fn as_optional_xml_text(&self) -> Result<Option<Cow<'_, str>>, Error>
Convert the value to an XML string in a context where an absent value can be represented.
The provided implementation will always return the result of
Self::as_xml_text wrapped into Some(.). By re-implementing
this method, implementors can customize the behaviour for certain
values.
Implementations on Foreign Types§
Source§impl AsXmlText for IpAddr
 
impl AsXmlText for IpAddr
Source§fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
 
fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
Convert core::net::IpAddr to XML text via Display.
This implementation never fails.
Source§impl AsXmlText for SocketAddr
 
impl AsXmlText for SocketAddr
Source§fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
 
fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
Convert core::net::SocketAddr to XML text via Display.
This implementation never fails.
Source§impl AsXmlText for Value
Available on crate feature serde_json only. 
impl AsXmlText for Value
serde_json only.Source§fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
 
fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
Convert serde_json::Value to XML text via Display.
This implementation never fails.
Source§impl AsXmlText for DomainPart
Available on crate feature jid only. 
impl AsXmlText for DomainPart
jid only.Source§fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
 
fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
Convert jid::DomainPart to XML text via Display.
This implementation never fails.
Source§impl AsXmlText for NodePart
Available on crate feature jid only. 
impl AsXmlText for NodePart
jid only.Source§fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
 
fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
Convert jid::NodePart to XML text via Display.
This implementation never fails.
Source§impl AsXmlText for ResourcePart
Available on crate feature jid only. 
impl AsXmlText for ResourcePart
jid only.Source§fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
 
fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
Convert jid::ResourcePart to XML text via Display.
This implementation never fails.
Source§impl AsXmlText for BareJid
Available on crate feature jid only. 
impl AsXmlText for BareJid
jid only.Source§fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
 
fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
Convert jid::BareJid to XML text via Display.
This implementation never fails.
Source§impl AsXmlText for FullJid
Available on crate feature jid only. 
impl AsXmlText for FullJid
jid only.Source§fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
 
fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
Convert jid::FullJid to XML text via Display.
This implementation never fails.
Source§impl AsXmlText for Ipv4Addr
 
impl AsXmlText for Ipv4Addr
Source§fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
 
fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
Convert core::net::Ipv4Addr to XML text via Display.
This implementation never fails.
Source§impl AsXmlText for Ipv6Addr
 
impl AsXmlText for Ipv6Addr
Source§fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
 
fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
Convert core::net::Ipv6Addr to XML text via Display.
This implementation never fails.
Source§impl AsXmlText for SocketAddrV4
 
impl AsXmlText for SocketAddrV4
Source§fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
 
fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
Convert core::net::SocketAddrV4 to XML text via Display.
This implementation never fails.
Source§impl AsXmlText for SocketAddrV6
 
impl AsXmlText for SocketAddrV6
Source§fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
 
fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
Convert core::net::SocketAddrV6 to XML text via Display.
This implementation never fails.
Source§impl AsXmlText for Uuid
Available on crate feature uuid only. 
impl AsXmlText for Uuid
uuid only.Source§fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
 
fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
Convert uuid::Uuid to XML text via Display.
This implementation never fails.
Source§impl AsXmlText for NonZeroI8
 
impl AsXmlText for NonZeroI8
Source§fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
 
fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
Convert core::num::NonZeroI8 to XML text via Display.
This implementation never fails.
Source§impl AsXmlText for NonZeroI16
 
impl AsXmlText for NonZeroI16
Source§fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
 
fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
Convert core::num::NonZeroI16 to XML text via Display.
This implementation never fails.
Source§impl AsXmlText for NonZeroI32
 
impl AsXmlText for NonZeroI32
Source§fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
 
fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
Convert core::num::NonZeroI32 to XML text via Display.
This implementation never fails.
Source§impl AsXmlText for NonZeroI64
 
impl AsXmlText for NonZeroI64
Source§fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
 
fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
Convert core::num::NonZeroI64 to XML text via Display.
This implementation never fails.
Source§impl AsXmlText for NonZeroI128
 
impl AsXmlText for NonZeroI128
Source§fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
 
fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
Convert core::num::NonZeroI128 to XML text via Display.
This implementation never fails.
Source§impl AsXmlText for NonZeroIsize
 
impl AsXmlText for NonZeroIsize
Source§fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
 
fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
Convert core::num::NonZeroIsize to XML text via Display.
This implementation never fails.
Source§impl AsXmlText for NonZeroU8
 
impl AsXmlText for NonZeroU8
Source§fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
 
fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
Convert core::num::NonZeroU8 to XML text via Display.
This implementation never fails.
Source§impl AsXmlText for NonZeroU16
 
impl AsXmlText for NonZeroU16
Source§fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
 
fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
Convert core::num::NonZeroU16 to XML text via Display.
This implementation never fails.
Source§impl AsXmlText for NonZeroU32
 
impl AsXmlText for NonZeroU32
Source§fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
 
fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
Convert core::num::NonZeroU32 to XML text via Display.
This implementation never fails.
Source§impl AsXmlText for NonZeroU64
 
impl AsXmlText for NonZeroU64
Source§fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
 
fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
Convert core::num::NonZeroU64 to XML text via Display.
This implementation never fails.
Source§impl AsXmlText for NonZeroU128
 
impl AsXmlText for NonZeroU128
Source§fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
 
fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
Convert core::num::NonZeroU128 to XML text via Display.
This implementation never fails.
Source§impl AsXmlText for NonZeroUsize
 
impl AsXmlText for NonZeroUsize
Source§fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
 
fn as_xml_text(&self) -> Result<Cow<'_, str>, Error>
Convert core::num::NonZeroUsize to XML text via Display.
This implementation never fails.