musli_core::de

Trait DecodeBytes

Source
pub trait DecodeBytes<'de, M>: Sized {
    // Required method
    fn decode_bytes<D>(cx: &D::Cx, decoder: D) -> Result<Self, D::Error>
       where D: Decoder<'de, Mode = M>;
}
Expand description

Trait governing how types are decoded as bytes.

This is typically used automatically through the #[musli(bytes)] attribute through the Decode derive.

§Examples

use musli::Decode;

#[derive(Decode)]
struct MyType {
    #[musli(bytes)]
    data: [u8; 128],
}

Implementing manually:

use musli::{Decode, Decoder};
use musli::de::DecodeBytes;

struct MyType {
    data: [u8; 128],
}

impl<'de, M> Decode<'de, M> for MyType {
    fn decode<D>(cx: &D::Cx, decoder: D) -> Result<Self, D::Error>
    where
        D: Decoder<'de>,
    {
        Ok(Self {
            data: DecodeBytes::decode_bytes(cx, decoder)?,
        })
    }
}

Required Methods§

Source

fn decode_bytes<D>(cx: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>,

Decode the given input as bytes.

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.

Implementations on Foreign Types§

Source§

impl<'de, M> DecodeBytes<'de, M> for &'de [u8]

Source§

fn decode_bytes<D>(cx: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de>,

Source§

impl<'de, M> DecodeBytes<'de, M> for Cow<'de, [u8]>

Source§

fn decode_bytes<D>(_: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>,

Source§

impl<'de, M> DecodeBytes<'de, M> for Box<[u8]>

Source§

fn decode_bytes<D>(cx: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>,

Source§

impl<'de, M> DecodeBytes<'de, M> for VecDeque<u8>

Source§

fn decode_bytes<D>(cx: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>,

Source§

impl<'de, M> DecodeBytes<'de, M> for Rc<[u8]>

Source§

fn decode_bytes<D>(cx: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>,

Source§

impl<'de, M> DecodeBytes<'de, M> for Arc<[u8]>

Source§

fn decode_bytes<D>(cx: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>,

Source§

impl<'de, M> DecodeBytes<'de, M> for Vec<u8>

Source§

fn decode_bytes<D>(_: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>,

Source§

impl<'de, M, const N: usize> DecodeBytes<'de, M> for [u8; N]

Source§

fn decode_bytes<D>(_: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de>,

Implementors§