Trait mayda::utility::Encode
[−]
[src]
pub trait Encode<B: Bits> { fn encode(&mut self, _: &[B]) -> Result<(), Error>; fn decode(&self) -> Vec<B>; fn decode_into(&self, _: &mut [B]) -> usize; }
Indicates that the type can be encoded and decoded by mayda
.
The default implementations of encode
and decode
return an error or
panic to indicate that there is no available specialization for the type.
This should not happen unless the user implements Bits
for some other
type or there is a library bug.
Required Methods
fn encode(&mut self, _: &[B]) -> Result<(), Error>
Encodes the slice into the Encode
object.
Errors
By convention, returns an error if the input slice contains more than the supported number of entries (currently 237 - 27).
fn decode(&self) -> Vec<B>
Decodes the contents of the Encode
object. Returns a vector because
ownership of the returned value must be given to the caller.
fn decode_into(&self, _: &mut [B]) -> usize
Decodes the contents of the Encode
object and writes the result into
the slice provided. More efficient than decode
if the slice is already
allocated. Returns the number of decoded entries.
Panics
By convention, panics if the slice is of insufficient length.