Skip to main content

TranscodeConverter

Trait TranscodeConverter 

Source
pub trait TranscodeConverter: Transcoder<Error = TranscodeConvertError<Self::DecodeError, Self::EncodeError, Self::Value>> {
    type DecodeError;
    type EncodeError;
    type Value;
}
Expand description

Converts encoded units of one representation into encoded units of another.

TranscodeConverter refines Transcoder for implementations whose input and output are both encoded unit streams. Any intermediate logical values are implementation details of the concrete converter.

The trait adds no methods. It exists to make generic bounds distinguish unit-to-unit conversion from value-to-unit encoding and unit-to-value decoding.

§Examples

use core::convert::Infallible;
use core::num::NonZeroUsize;

use qubit_codec::CapacityError;
use qubit_codec::TranscodeConvertError;
use qubit_codec::TranscodeConverter;
use qubit_codec::TranscodeProgress;
use qubit_codec::Transcoder;

#[derive(Default)]
struct ByteToWord;
impl TranscodeConverter for ByteToWord {
    type DecodeError = Infallible;
    type EncodeError = Infallible;
    type Value = u8;
}

let mut converter = ByteToWord::default();
let mut output = [0_u16; 2];
assert_eq!(converter.reset(&mut output, 0).unwrap(), 0);
let progress = converter.transcode(&[7, 9], 0, &mut output, 0).unwrap();
assert_eq!(output, [7, 9]);
assert_eq!(progress, TranscodeProgress::complete(2, 2));
assert_eq!(converter.finish(&mut output, progress.written()).unwrap(), 0);

Required Associated Types§

Source

type DecodeError

Domain error type produced by source decoding.

Source

type EncodeError

Domain error type produced by target encoding.

Source

type Value

Intermediate logical value type converted between source and target.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§