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§
sourcefn from_utf_32(data_utf_32: &Utf32) -> Self
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.
sourcefn to_utf_32(&self) -> Utf32
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.
sourcefn from_bytes_no_check(
bytes: &[u8],
big_endian: bool
) -> Result<Self, UnicodeEncodingError>where
Self: Sized,
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.
Provided Methods§
sourcefn to_string(&self) -> String
fn to_string(&self) -> String
Converts an Unicode encoded content and converts it to Rust’s string.
sourcefn from_string(s: &str) -> Result<Self, UnicodeEncodingError>where
Self: Sized,
fn from_string(s: &str) -> Result<Self, UnicodeEncodingError>where Self: Sized,
Takes a Rust string and converts it into Unicode encoded content.
sourcefn convert_to<T: UnicodeEncoding>(&self) -> T
fn convert_to<T: UnicodeEncoding>(&self) -> T
Converts from one Unicode encoding to an other.
sourcefn content_eq<T: UnicodeEncoding>(&self, other: &T) -> bool
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.
sourcefn check_sanity(&self) -> UnicodeEncodingError
fn check_sanity(&self) -> UnicodeEncodingError
Checks that the unicode data is valid.
sourcefn from_bytes(
bytes: &[u8],
big_endian: bool
) -> Result<Self, UnicodeEncodingError>where
Self: Sized,
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.
sourcefn from_file(
filename: &str,
big_endian: bool
) -> Result<Result<Self, UnicodeEncodingError>, Error>where
Self: Sized,
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.