Trait TextCodec

Source
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:

  1. The type originates in a foreign crate, preventing the implementation of foreign traits.

  2. 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§

Source

fn decode(s: String) -> Result<T, Error>

Decode a string value into the type.

Source

fn encode(value: &T) -> Result<Option<Cow<'_, str>>, Error>

Encode the type as string value.

If this returns None, the string value is not emitted at all.

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§

Source§

impl TextCodec<Option<String>> for EmptyAsNone

Source§

impl TextCodec<String> for EmptyAsError

Source§

impl TextCodec<String> for Plain

Source§

impl TextCodec<Vec<u8>> for ColonSeparatedHex

Source§

impl<'x, Filter: TextFilter> TextCodec<Cow<'x, [u8]>> for Base64<Filter>

Available on crate feature base64 only.
Source§

impl<Filter: TextFilter> TextCodec<Vec<u8>> for Base64<Filter>

Available on crate feature base64 only.
Source§

impl<T, Filter: TextFilter> TextCodec<Option<T>> for Base64<Filter>
where Base64<Filter>: TextCodec<T>,

Available on crate feature base64 only.
Source§

impl<T, const N: usize> TextCodec<Option<T>> for FixedHex<N>
where FixedHex<N>: TextCodec<T>,

Source§

impl<const N: usize> TextCodec<[u8; N]> for FixedHex<N>