Trait Binary

Source
pub trait Binary
where Self: Sized,
{ // Required methods fn from_bytes(bytes: &[u8]) -> Option<Self>; fn as_bytes(&self) -> Vec<u8> ; }
Expand description

Trait for binary conversion.

  • Self::as_bytes is used to create a binary representation of this instance.
  • The Self::from_bytes method is used to convert the binary data back to its instance.

Required Methods§

Source

fn from_bytes(bytes: &[u8]) -> Option<Self>

Creates an instance of Self based on its binary representation.

On success an instance of Self wrapped into a Some is returned. On any error None is returned.

Source

fn as_bytes(&self) -> Vec<u8>

Creates the binary representation of self.

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§