pub trait Encoding: Send + Sync {
// Required methods
fn encode_to_slice(
&self,
src: &[u8],
dst: &mut [u8],
) -> Result<usize, Error>;
fn encoded_len(&self, bytes: &[u8]) -> usize;
fn decode_to_slice(
&self,
src: &[u8],
dst: &mut [u8],
) -> Result<usize, Error>;
fn decoded_len(&self, encoded_bytes: &[u8]) -> Result<usize, Error>;
// Provided methods
fn encode<B: AsRef<[u8]>>(&self, bytes: B) -> Vec<u8> ⓘ { ... }
fn encode_to_string<B: AsRef<[u8]>>(
&self,
bytes: B,
) -> Result<String, Error> { ... }
fn encode_to_writer<B, W>(
&self,
bytes: B,
writer: &mut W,
) -> Result<usize, Error>
where B: AsRef<[u8]>,
W: Write { ... }
fn encode_to_file<B, P>(&self, bytes: B, path: P) -> Result<File, Error>
where B: AsRef<[u8]>,
P: AsRef<Path> { ... }
fn decode<B: AsRef<[u8]>>(&self, encoded_bytes: B) -> Result<Vec<u8>, Error> { ... }
fn decode_from_str<S: AsRef<str>>(
&self,
encoded: S,
) -> Result<Vec<u8>, Error> { ... }
fn decode_from_reader<R: Read>(
&self,
reader: &mut R,
) -> Result<Vec<u8>, Error> { ... }
fn decode_from_file<P: AsRef<Path>>(
&self,
path: P,
) -> Result<Vec<u8>, Error> { ... }
}
Expand description
All encoding types in this crate implement this trait
Required Methods§
Sourcefn encode_to_slice(&self, src: &[u8], dst: &mut [u8]) -> Result<usize, Error>
fn encode_to_slice(&self, src: &[u8], dst: &mut [u8]) -> Result<usize, Error>
Encode the given slice into the destination buffer.
Returns the size of the encoded output, or Error
if the destination
buffer was too small to hold the encoded output.
Sourcefn encoded_len(&self, bytes: &[u8]) -> usize
fn encoded_len(&self, bytes: &[u8]) -> usize
Calculate the length of the given data after encoding.
Provided Methods§
Sourcefn encode<B: AsRef<[u8]>>(&self, bytes: B) -> Vec<u8> ⓘ
fn encode<B: AsRef<[u8]>>(&self, bytes: B) -> Vec<u8> ⓘ
Encode the given buffer, returning a Vec<u8>
Sourcefn encode_to_string<B: AsRef<[u8]>>(&self, bytes: B) -> Result<String, Error>
fn encode_to_string<B: AsRef<[u8]>>(&self, bytes: B) -> Result<String, Error>
Encode the given slice to a String
with this Encoding
.
Returns an Error
in the event this encoding does not produce a
well-formed UTF-8 string.
Sourcefn encode_to_writer<B, W>(
&self,
bytes: B,
writer: &mut W,
) -> Result<usize, Error>
fn encode_to_writer<B, W>( &self, bytes: B, writer: &mut W, ) -> Result<usize, Error>
Encode the given slice with this Encoding
, writing the result to the
supplied io::Write
type, returning the number of bytes written or a Error
.
Sourcefn encode_to_file<B, P>(&self, bytes: B, path: P) -> Result<File, Error>
fn encode_to_file<B, P>(&self, bytes: B, path: P) -> Result<File, Error>
Encode self
and write it to a file at the given path, returning the
resulting File
or a Error
.
If the file does not exist, it will be created with a mode of
FILE_MODE
(i.e. 600
). If the file does exist, it will be erased
and replaced.
Sourcefn decode<B: AsRef<[u8]>>(&self, encoded_bytes: B) -> Result<Vec<u8>, Error>
fn decode<B: AsRef<[u8]>>(&self, encoded_bytes: B) -> Result<Vec<u8>, Error>
Decode the given buffer, returning a Vec<u8>
Sourcefn decode_from_str<S: AsRef<str>>(&self, encoded: S) -> Result<Vec<u8>, Error>
fn decode_from_str<S: AsRef<str>>(&self, encoded: S) -> Result<Vec<u8>, Error>
Decode the given string-alike type with this Encoding
, returning the
decoded value or a Error
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.