Struct musli::compat::Packed

source ·
#[repr(transparent)]
pub struct Packed<T>(pub T);
Expand description

Treat T as if its packed.

This is for example implemented for tuples.

§Examples

use musli::{Decode, Decoder};
use musli::compat::Packed;

struct Struct {
    field: u8,
    field2: u32,
}

impl<'de, M> Decode<'de, M> for Struct
where
    Packed<(u8, u32)>: Decode<'de, M>
{
    fn decode<D>(cx: &D::Cx, decoder: D) -> Result<Self, D::Error>
    where
        D: Decoder<'de, Mode = M>,
    {
        let Packed((field, field2)) = Decode::decode(cx, decoder)?;

        Ok(Struct {
            field,
            field2,
        })
    }
}

Tuple Fields§

§0: T

Trait Implementations§

source§

impl<'de, T> Decode<'de, Binary> for Packed<T>

source§

fn decode<D>( _ctx: &D::Cx, _decoder: D ) -> Result<Self, <D::Cx as Context>::Error>
where D: Decoder<'de, Mode = Binary>,

Decode the given input.
source§

impl<'de, T> Decode<'de, Text> for Packed<T>
where T: EncodePacked<Text> + DecodePacked<'de, Text>,

source§

fn decode<D>( _ctx: &D::Cx, _decoder: D ) -> Result<Self, <D::Cx as Context>::Error>
where D: Decoder<'de, Mode = Text>,

Decode the given input.
source§

impl<T> Encode<Binary> for Packed<T>
where T: EncodePacked<Binary>,

source§

fn encode<E>( &self, _ctx: &E::Cx, _encoder: E ) -> Result<<E as Encoder>::Ok, <E as Encoder>::Error>
where E: Encoder<Mode = Binary>,

Encode the given output.
source§

impl<T> Encode<Text> for Packed<T>
where T: EncodePacked<Text>,

source§

fn encode<E>( &self, _ctx: &E::Cx, _encoder: E ) -> Result<<E as Encoder>::Ok, <E as Encoder>::Error>
where E: Encoder<Mode = Text>,

Encode the given output.

Auto Trait Implementations§

§

impl<T> Freeze for Packed<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Packed<T>
where T: RefUnwindSafe,

§

impl<T> Send for Packed<T>
where T: Send,

§

impl<T> Sync for Packed<T>
where T: Sync,

§

impl<T> Unpin for Packed<T>
where T: Unpin,

§

impl<T> UnwindSafe for Packed<T>
where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<M, D> DecodeOwned<M> for D
where D: for<'de> Decode<'de, M>,