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§
Sourcefn decode<'a>(&self, bytes: &'a [u8]) -> Result<Cow<'a, str>, DecodeError>
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.
fn encode<'a>(&self, s: &'a str) -> Result<Cow<'a, [u8]>, EncodeError>
Trait Implementations§
Implementors§
impl Encoding for Ascii
Tries to decode as ASCII, if unrepresentable characters are found, an Err is returned.
impl Encoding for Unicode
Tries to decode as Unicode, if unrepresentable characters are found, an Err is returned.
impl Encoding for UnicodeLossy
Tries to decode as Unicode, replaces unknown codepoints with the replacement character.