pub trait Codec {
type ExpandError: Error;
// Required methods
fn compress_line(&self, line: &str) -> String;
fn expand_line(&self, line: &str) -> Result<String, Self::ExpandError>;
// Provided methods
fn compress(
&self,
r: &mut impl BufRead,
w: &mut impl Write,
) -> Result<(), Error> { ... }
fn expand(
&self,
r: &mut impl BufRead,
w: &mut impl Write,
) -> Result<(), TranscodeError<Self::ExpandError>> { ... }
}
Expand description
The specification of a codec.
Codecs work line by line. As such, they require two method implementations:
compress_line
— to encode one line of input text, and
expand_line
— to perform the reverse operation.
Compression is not allowed to return an error; the thinking is that all text should be compressible. Expansion, however, may return an error. It is possible that the output of compression may have been mangled with, in which case expansion is not possible.
Required Associated Types§
Sourcetype ExpandError: Error
type ExpandError: Error
The type of error returned during expansion.
Required Methods§
Sourcefn compress_line(&self, line: &str) -> String
fn compress_line(&self, line: &str) -> String
Compresses a line of text, returning its encoded representation as a String
.
Sourcefn expand_line(&self, line: &str) -> Result<String, Self::ExpandError>
fn expand_line(&self, line: &str) -> Result<String, Self::ExpandError>
Expands a line of text, returning its decoded representation as a String
.
§Errors
Expansion is not always possible, in which case an ExpandError
is returned.
Provided Methods§
Sourcefn expand(
&self,
r: &mut impl BufRead,
w: &mut impl Write,
) -> Result<(), TranscodeError<Self::ExpandError>>
fn expand( &self, r: &mut impl BufRead, w: &mut impl Write, ) -> Result<(), TranscodeError<Self::ExpandError>>
A helper method for expanding a series of lines from a given buffered reader, outputting the result into the given writer.
§Errors
TranscodeError
if the reader or the writer encountered an I/O error, or
if the codec was unable to expand a line.
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.