Trait dbase::encoding::Encoding

source ·
pub trait Encoding: EncodingClone + AsCodePageMark + Send {
    // Required methods
    fn decode<'a>(&self, bytes: &'a [u8]) -> Result<Cow<'a, str>, DecodeError>;
    fn encode<'a>(&self, s: &'a str) -> Result<Cow<'a, [u8]>, EncodeError>;
}
Expand description

Trait for reading strings from the database files.

If the yore feature isn’t on, this is implemented only by UnicodeLossy and Unicode.

If the yore feature is on, this is implemented by all yore::CodePage.

Note: This trait might be extended with an encode function in the future.

Required Methods§

source

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

Decode encoding into UTF-8 string. If codepoints can’t be represented, an error is returned.

source

fn encode<'a>(&self, s: &'a str) -> Result<Cow<'a, [u8]>, EncodeError>

Trait Implementations§

source§

impl Clone for Box<dyn Encoding>

source§

fn clone(&self) -> Box<dyn Encoding>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Implementors§

source§

impl Encoding for Ascii

Tries to decode as ASCII, if unrepresentable characters are found, an Err is returned.

source§

impl Encoding for Unicode

Tries to decode as Unicode, if unrepresentable characters are found, an Err is returned.

source§

impl Encoding for UnicodeLossy

Tries to decode as Unicode, replaces unknown codepoints with the replacement character.

source§

impl<CP> Encoding for LossyCodePage<CP>
where CP: 'static + CodePage + Clone + AsCodePageMark + Send,

source§

impl<T> Encoding for T
where T: 'static + CodePage + Clone + AsCodePageMark + Send,