Codec

Trait Codec 

Source
pub trait Codec:
    Debug
    + Copy
    + Clone
    + PartialEq
    + Hash
    + Eq {
    const BITS: u8;

    // Required methods
    fn unsafe_from_bits(b: u8) -> Self;
    fn try_from_bits(b: u8) -> Option<Self>;
    fn unsafe_from_ascii(c: u8) -> Self;
    fn try_from_ascii(c: u8) -> Option<Self>;
    fn to_char(self) -> char;
    fn to_bits(self) -> u8;
    fn items() -> impl Iterator<Item = Self>;
}
Expand description

The binary encoding of an alphabet’s symbols can be represented with any type. Encoding from ASCII bytes and decoding the representation is implemented through the Codec trait.

The intended representation is an Enum, transparently represented as a u8.

Required Associated Constants§

Source

const BITS: u8

The number of bits used to encode the symbols. e.g. Dna::BITS = 2, Iupac::BITS = 4.

Required Methods§

Source

fn unsafe_from_bits(b: u8) -> Self

Convert raw bits of binary encoding into enum item. Binary values that don’t match an enum member’s discriminant will result in panic or random enum item

Source

fn try_from_bits(b: u8) -> Option<Self>

Fallibly convert raw bits into enum. If the binary value does not match a discriminant, return None

Source

fn unsafe_from_ascii(c: u8) -> Self

Encode an ASCII byte as a codec enum item

Source

fn try_from_ascii(c: u8) -> Option<Self>

Fallibly encode an ASCII byte as a codec enum item

Source

fn to_char(self) -> char

Decode enum item as a UTF-8 character

Source

fn to_bits(self) -> u8

Encode as raw bits

Source

fn items() -> impl Iterator<Item = Self>

Iterator over the symbols of the codec

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.

Implementors§

Source§

impl Codec for Amino

Source§

const BITS: u8 = 6u8

Source§

impl Codec for MK

Source§

const BITS: u8 = 1u8

Source§

impl Codec for RY

Source§

const BITS: u8 = 1u8

Source§

impl Codec for WS

Source§

const BITS: u8 = 1u8

Source§

impl Codec for bio_seq::codec::dna::Dna

Source§

const BITS: u8 = 2u8

Source§

impl Codec for bio_seq::codec::iupac::Iupac

Source§

const BITS: u8 = 4u8

Source§

impl Codec for bio_seq::codec::masked::dna::Dna

Source§

const BITS: u8 = 4u8

Source§

impl Codec for bio_seq::codec::masked::iupac::Iupac

Source§

const BITS: u8 = 5u8

Source§

impl Codec for bio_seq::codec::text::Dna

Source§

const BITS: u8 = 8u8