pub trait TextCodec<T> {
// Required methods
fn decode(s: String) -> Result<T, Error>;
fn encode(value: &T) -> Result<Option<Cow<'_, str>>, Error>;
}Expand description
Represent a way to encode/decode text data into a Rust type.
This trait can be used in scenarios where implementing FromXmlText
and/or AsXmlText on a type is not feasible or sensible, such as the
following:
-
The type originates in a foreign crate, preventing the implementation of foreign traits.
-
There is more than one way to convert a value to/from XML.
The codec to use for a text can be specified in the attributes understood
by FromXml and AsXml derive macros. See the documentation of the
FromXml derive macro for details.
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl TextCodec<Option<String>> for EmptyAsNone
impl TextCodec<String> for EmptyAsError
impl TextCodec<String> for Plain
impl TextCodec<Vec<u8>> for ColonSeparatedHex
impl<'x, Filter: TextFilter> TextCodec<Cow<'x, [u8]>> for Base64<Filter>
Available on crate feature
base64 only.impl<Filter: TextFilter> TextCodec<Vec<u8>> for Base64<Filter>
Available on crate feature
base64 only.impl<T, Filter: TextFilter> TextCodec<Option<T>> for Base64<Filter>
Available on crate feature
base64 only.