Skip to main content

Module containers

Module containers 

Source
Expand description

This module provides specialized implementations of standard library collection types that provide control over the length encoding (see SeqLen), as well as special case opt-in raw-copy overrides (see pod_wrapper!).

§Examples

Raw byte vec with UseIntLen<u16> length encoding:

#[derive(SchemaWrite, SchemaRead, PartialEq, Debug)]
struct MyStruct {
    #[wincode(with = "containers::Vec<_, UseIntLen<u16>>")]
    vec: Vec<u8>,
}

let my_struct = MyStruct { vec: vec![1, 2, 3] };
let bytes = wincode::serialize(&my_struct).unwrap();
assert_eq!(bytes.len(), size_of::<u16>() + my_struct.vec.len() * size_of::<u8>());
assert_eq!(my_struct, wincode::deserialize(&bytes).unwrap());

Vector with struct elements and UseIntLen<u16> length encoding:

#[derive(SchemaWrite, SchemaRead, PartialEq, Debug)]
struct Point {
    x: u64,
    y: u64,
}

#[derive(SchemaWrite, SchemaRead, PartialEq, Debug)]
struct MyStruct {
    #[wincode(with = "containers::Vec<Point, UseIntLen<u16>>")]
    vec: Vec<Point>,
}

let my_struct = MyStruct {
    vec: vec![Point { x: 1, y: 2 }, Point { x: 3, y: 4 }],
};
let bytes = wincode::serialize(&my_struct).unwrap();
assert_eq!(bytes.len(), size_of::<u16>() + my_struct.vec.len() * size_of::<Point>());
assert_eq!(my_struct, wincode::deserialize(&bytes).unwrap());

Macros§

pod_wrapper
Creates a wrapper type for a type that is represented by raw bytes and does not have any invalid bit patterns.

Structs§

Arc
Like Box, for Arc.
BinaryHeap
A BinaryHeap with a customizable length encoding.
Box
A Box<[T]> with a customizable length encoding.
FromIntoIterator
A generic sequence schema for custom collections that implement FromIterator (for reading) and whose references implement IntoIterator with an ExactSizeIterator (for writing).
Rc
Like Box, for Rc.
Vec
A Vec with a customizable length encoding.
VecDeque
A VecDeque with a customizable length encoding.

Functions§

decode_into_slice_t
Decode slice.len() items of T into contiguous, uninitialized memory.
encode_from_iter
Like encode_from_iter_prealloc_check, but skips the preallocation size check.
encode_from_iter_prealloc_check
Encode a sequence of T from an iterator into the Writer.