Skip to main content

Encode

Trait Encode 

Source
pub trait Encode: Shape {
    // Required method
    fn encode<R>(&self, f: impl FnOnce(&[u8]) -> R) -> R;
}
Expand description

A type that can be written into a record.

Implemented for a borrowed form as well as an owned one, so that a lookup can take &str where the collection holds String, exactly as HashMap<String, _>::get does.

Required Methods§

Source

fn encode<R>(&self, f: impl FnOnce(&[u8]) -> R) -> R

Hand the bytes of self to f.

A callback rather than a returned Vec because a returned Vec is an allocation, and this is the write path. A type whose bytes are already contiguous passes them straight through, and a fixed width one builds them on the stack.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementations on Foreign Types§

Source§

impl Encode for String

Source§

fn encode<R>(&self, f: impl FnOnce(&[u8]) -> R) -> R

Source§

impl Encode for Vec<u8>

Source§

fn encode<R>(&self, f: impl FnOnce(&[u8]) -> R) -> R

Source§

impl Encode for [u8]

Source§

fn encode<R>(&self, f: impl FnOnce(&[u8]) -> R) -> R

Source§

impl Encode for bool

Source§

fn encode<R>(&self, f: impl FnOnce(&[u8]) -> R) -> R

Source§

impl Encode for f32

Source§

fn encode<R>(&self, f: impl FnOnce(&[u8]) -> R) -> R

Source§

impl Encode for f64

Source§

fn encode<R>(&self, f: impl FnOnce(&[u8]) -> R) -> R

Source§

impl Encode for i8

Source§

fn encode<R>(&self, f: impl FnOnce(&[u8]) -> R) -> R

Source§

impl Encode for i16

Source§

fn encode<R>(&self, f: impl FnOnce(&[u8]) -> R) -> R

Source§

impl Encode for i32

Source§

fn encode<R>(&self, f: impl FnOnce(&[u8]) -> R) -> R

Source§

impl Encode for i64

Source§

fn encode<R>(&self, f: impl FnOnce(&[u8]) -> R) -> R

Source§

impl Encode for str

Source§

fn encode<R>(&self, f: impl FnOnce(&[u8]) -> R) -> R

Source§

impl Encode for u8

Source§

fn encode<R>(&self, f: impl FnOnce(&[u8]) -> R) -> R

Source§

impl Encode for u16

Source§

fn encode<R>(&self, f: impl FnOnce(&[u8]) -> R) -> R

Source§

impl Encode for u32

Source§

fn encode<R>(&self, f: impl FnOnce(&[u8]) -> R) -> R

Source§

impl Encode for u64

Source§

fn encode<R>(&self, f: impl FnOnce(&[u8]) -> R) -> R

Implementors§