Trait jomini::Encoding

source ·
pub trait Encoding {
    // Required method
    fn decode<'a>(&self, data: &'a [u8]) -> Cow<'a, str>;
}
Expand description

An encoding for interpreting byte data as UTF-8 text

Used in both text and binary format deserializers

It is heavily encouraged that encoding implementations are marked as Copy to make sure they are as cheap to copy as possible. In an experiment storing the encoding in a Rc resulted in a decrease of deserialization throughput by over 10%, as encodings are passed around everywhere.

An encoding should also perform additional actions when:

  • trailing whitespace is removed
  • escape sequences are unescaped

Required Methods§

source

fn decode<'a>(&self, data: &'a [u8]) -> Cow<'a, str>

Decodes bytes into a utf-8 compatible string – allocating if necessary

Implementations on Foreign Types§

source§

impl<T: Encoding + ?Sized> Encoding for &T

source§

fn decode<'a>(&self, data: &'a [u8]) -> Cow<'a, str>

source§

impl<T: Encoding + ?Sized> Encoding for Box<T>

source§

fn decode<'a>(&self, data: &'a [u8]) -> Cow<'a, str>

Implementors§

source§

impl Encoding for Utf8Encoding

source§

impl Encoding for Windows1252Encoding

source§

impl<'data, 'tokens, E> Encoding for ValueReader<'data, 'tokens, E>
where E: Encoding,