Box

Struct Box 

Source
pub struct Box<T: ?Sized, Len = BincodeLen>(/* private fields */);
Available on crate feature alloc only.
Expand description

A Box<[T]> with a customizable length encoding and optimized read/write implementation for Pod.

§Examples

#[derive(Serialize, Deserialize, Clone, Copy)]
#[repr(transparent)]
struct Address([u8; 32]);

#[derive(Serialize, Deserialize, SchemaWrite, SchemaRead)]
struct MyStruct {
    #[wincode(with = "containers::Box<[Pod<Address>]>")]
    address: Box<[Address]>
}

let my_struct = MyStruct {
    address: vec![Address(array::from_fn(|i| i as u8)); 10].into_boxed_slice(),
};
let wincode_bytes = wincode::serialize(&my_struct).unwrap();
let bincode_bytes = bincode::serialize(&my_struct).unwrap();
assert_eq!(wincode_bytes, bincode_bytes);

Trait Implementations§

Source§

impl<T, Len> SchemaRead<'_> for Box<[Pod<T>], Len>
where Len: SeqLen, T: Copy + 'static,

Source§

type Dst = Box<[T]>

Source§

fn read( reader: &mut Reader<'_>, dst: &mut MaybeUninit<Self::Dst>, ) -> ReadResult<()>

Read into dst from reader. Read more
Source§

fn get(reader: &mut Reader<'de>) -> ReadResult<Self::Dst>

Read Self::Dst from reader into a new Self::Dst.
Source§

impl<'de, T, Len> SchemaRead<'de> for Box<[Elem<T>], Len>
where Len: SeqLen, T: SchemaRead<'de>,

Source§

type Dst = Box<[<T as SchemaRead<'de>>::Dst]>

Source§

fn read( reader: &mut Reader<'de>, dst: &mut MaybeUninit<Self::Dst>, ) -> ReadResult<()>

Read into dst from reader. Read more
Source§

fn get(reader: &mut Reader<'de>) -> ReadResult<Self::Dst>

Read Self::Dst from reader into a new Self::Dst.
Source§

impl<T, Len> SchemaWrite for Box<[Elem<T>], Len>
where Len: SeqLen, T: SchemaWrite, T::Src: Sized,

Source§

type Src = Box<[<T as SchemaWrite>::Src]>

Source§

fn size_of(src: &Self::Src) -> WriteResult<usize>

Get the serialized size of Self::Src.
Source§

fn write(writer: &mut Writer<'_>, src: &Self::Src) -> WriteResult<()>

Write Self::Src to writer.
Source§

impl<T, Len> SchemaWrite for Box<[Pod<T>], Len>
where Len: SeqLen, T: Copy + 'static,

Source§

type Src = Box<[T]>

Source§

fn size_of(src: &Self::Src) -> WriteResult<usize>

Get the serialized size of Self::Src.
Source§

fn write(writer: &mut Writer<'_>, src: &Self::Src) -> WriteResult<()>

Write Self::Src to writer.

Auto Trait Implementations§

§

impl<T, Len> Freeze for Box<T, Len>
where T: ?Sized,

§

impl<T, Len> RefUnwindSafe for Box<T, Len>
where T: RefUnwindSafe + ?Sized, Len: RefUnwindSafe,

§

impl<T, Len> Send for Box<T, Len>
where T: Send + ?Sized, Len: Send,

§

impl<T, Len> Sync for Box<T, Len>
where T: Sync + ?Sized, Len: Sync,

§

impl<T, Len> Unpin for Box<T, Len>
where T: Unpin + ?Sized, Len: Unpin,

§

impl<T, Len> UnwindSafe for Box<T, Len>
where T: UnwindSafe + ?Sized, Len: 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<'de, T> Deserialize<'de> for T
where T: SchemaRead<'de>,

Source§

fn deserialize(bytes: &'de [u8]) -> ReadResult<Self::Dst>

Deserialize bytes into a new Self::Dst.
Source§

fn deserialize_into( bytes: &'de [u8], target: &mut MaybeUninit<Self::Dst>, ) -> ReadResult<()>

Deserialize bytes into target.
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> Serialize for T
where T: SchemaWrite + ?Sized,

Source§

fn serialize(src: &Self::Src) -> WriteResult<Vec<u8>>

Available on crate feature alloc only.
Serialize a serializable type into a Vec of bytes.
Source§

fn serialize_into( src: &Self::Src, target: &mut [MaybeUninit<u8>], ) -> WriteResult<usize>

Serialize a serializable type into the given byte buffer. Read more
Source§

fn serialized_size(src: &Self::Src) -> WriteResult<u64>

Get the size in bytes of the type when serialized.
Source§

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

Source§

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>,

Source§

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.