Skip to main content

Input

Trait Input 

Source
pub trait Input: Into<Self::Buf> {
    type Buf: Buf;
}
Expand description

An input that can be consumed by a decoder.

Buf inputs pass through unchanged. A Vec<u8> transfers its allocation to Bytes without copying its payload. Custom inputs can convert into a Buf.

Borrowing an owned buffer as a slice discards its ability to share decoded byte fields, so slices require an explicit Copying adapter:

ⓘ
use bytes::Bytes;
use commonware_codec::{Decode, Encode};

let encoded = Bytes::from_static(b"hello").encode();
let _ = Bytes::decode_cfg(encoded.as_ref(), &(..).into());

Owning storage is insufficient if the buffer’s byte extraction copies it:

ⓘ
use bytes::Bytes;
use commonware_codec::{Decode, Encode};
use std::io::Cursor;

let encoded = Bytes::from_static(b"hello").encode();
let _ = Bytes::decode_cfg(Cursor::new(encoded), &(..).into());

Required Associated Types§

Source

type Buf: Buf

The buffer used by the decoder.

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 Input for Vec<u8>

Implementors§

Source§

impl<B: Buf> Input for B

Source§

type Buf = B