Trait serbzip_core::codecs::Codec
source · [−]pub trait Codec {
type ExpandError: Error;
fn compress_line(&self, line: &str) -> String;
fn expand_line(&self, line: &str) -> Result<String, Self::ExpandError>;
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
type ExpandError: Error
type ExpandError: Error
The type of error returned during expansion.
Required Methods
fn 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.
fn 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
fn 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.