pub trait UnicodeEncoding {
    // Required methods
    fn from_utf_32(data_utf_32: &Utf32) -> Self;
    fn to_utf_32(&self) -> Utf32;
    fn from_bytes_no_check(
        bytes: &[u8],
        big_endian: bool
    ) -> Result<Self, UnicodeEncodingError>
       where Self: Sized;
    fn to_bytes(&self, big_endian: bool) -> Vec<u8>;

    // Provided methods
    fn to_string(&self) -> String { ... }
    fn from_string(s: &str) -> Result<Self, UnicodeEncodingError>
       where Self: Sized { ... }
    fn convert_to<T: UnicodeEncoding>(&self) -> T { ... }
    fn content_eq<T: UnicodeEncoding>(&self, other: &T) -> bool { ... }
    fn check_sanity(&self) -> UnicodeEncodingError { ... }
    fn from_bytes(
        bytes: &[u8],
        big_endian: bool
    ) -> Result<Self, UnicodeEncodingError>
       where Self: Sized { ... }
    fn from_file(
        filename: &str,
        big_endian: bool
    ) -> Result<Result<Self, UnicodeEncodingError>, Error>
       where Self: Sized { ... }
    fn to_file(data: &Self, filename: &str, big_endian: bool) -> Option<Error> { ... }
}
Expand description

The UnicodeEncoding trait contains the basic function shared with all the other encodings in this crate. This is converting the data from and to UTF-32 and writing it to or reading it from a file. Furthermore, it is also possible to convert from and to a slice of bytes.

Required Methods§

source

fn from_utf_32(data_utf_32: &Utf32) -> Self

The function from_utf_32 takes a Utf32 struct and convert its content to the desired encoding. This function should always be implemented by the encoding’s type.

source

fn to_utf_32(&self) -> Utf32

The function to_utf_32 converts data from the desired encoding to UTF-32. It should always be implemented by the encoding’s type.

source

fn from_bytes_no_check( bytes: &[u8], big_endian: bool ) -> Result<Self, UnicodeEncodingError>where Self: Sized,

The function from_bytes_no_check takes a stream of bytes and interpret it as it was in the desired encoding. It should always be implemented by the encoding’s type. This does not uses the check_sanity function.

source

fn to_bytes(&self, big_endian: bool) -> Vec<u8>

The function to_bytes takes the raw-data of encoded content and convert it to a vector of bytes. It should always be implemented by the encoding’s type.

Provided Methods§

source

fn to_string(&self) -> String

Converts an Unicode encoded content and converts it to Rust’s string.

source

fn from_string(s: &str) -> Result<Self, UnicodeEncodingError>where Self: Sized,

Takes a Rust string and converts it into Unicode encoded content.

source

fn convert_to<T: UnicodeEncoding>(&self) -> T

Converts from one Unicode encoding to an other.

source

fn content_eq<T: UnicodeEncoding>(&self, other: &T) -> bool

Tell if the encoded content is equal to an other encoded content, regardless of the chosen encoding.

source

fn check_sanity(&self) -> UnicodeEncodingError

Checks that the unicode data is valid.

source

fn from_bytes( bytes: &[u8], big_endian: bool ) -> Result<Self, UnicodeEncodingError>where Self: Sized,

The function from_bytes takes a stream of bytes and interpret it as it was in the desired encoding. It should always be implemented by the encoding’s type.

source

fn from_file( filename: &str, big_endian: bool ) -> Result<Result<Self, UnicodeEncodingError>, Error>where Self: Sized,

Reads a file containing data encoded in an Unicode. If the file can’t be opened, an io error is returned. If the file can be open but the data is not valid, an UnicodeEncodingError will be returned. If everything goes well, the data is returned.

source

fn to_file(data: &Self, filename: &str, big_endian: bool) -> Option<Error>

Writes Unicode data to a file. If that can be done, None is returned. If there is an IO error, the IO error is returned in the Some.

Implementors§