Skip to main content

InputCodec

Trait InputCodec 

Source
pub trait InputCodec<T>: Send + Sync {
    // Required methods
    fn metadata(&self) -> &'static CodecMetadata;
    fn read(&self, reader: &mut dyn Read) -> Result<T, InputCodecError>;

    // Provided methods
    fn read_path(&self, path: &Path) -> Result<T, InputCodecError> { ... }
    fn decode(&self, input: &str) -> Result<T, InputCodecError> { ... }
    fn read_bytes(&self, input: &[u8]) -> Result<T, InputCodecError> { ... }
}
Expand description

Decode a byte stream into a value of type T.

Required Methods§

Source

fn metadata(&self) -> &'static CodecMetadata

Return static codec metadata. This must not read or parse input.

Source

fn read(&self, reader: &mut dyn Read) -> Result<T, InputCodecError>

Decode a byte stream.

Provided Methods§

Source

fn read_path(&self, path: &Path) -> Result<T, InputCodecError>

Decode a file. Codecs with path-relative semantics may override this method.

Source

fn decode(&self, input: &str) -> Result<T, InputCodecError>

Decode UTF-8 text.

Source

fn read_bytes(&self, input: &[u8]) -> Result<T, InputCodecError>

Decode an in-memory byte sequence.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§