serial_traits
A trait that allows you to serialize to and parse from Vec<u8> buffers.
This is great for sending them across for example tcp or ws sockets.
Comes with implementations for primitive types, String and generic collection types, so long the item type implements the trait too.
The buffer is no more larger than what you serialized, if you serialize a struct with two f32s, the final buffer will be 8 bytes large.
(PS: Variable-sized collections, to keep track of the size of the collection, are prefixed with u32.)
Using types that implement the trait:
// this is the trait
use Serializable;
// serializing a type that implements it
let mut buffer: = 6754_u16.serialize;
// deserializing a type that implements it
match u16parse
// the parse function consumes the buffer
assert_eq;
Implementing the trait for your own structs:
Types with Serializable implemented:
f32,f64u8,u16,u32,u64,u128i8,i16,i32,i64,i128char,bool[T; N]StringVec<T>,VecDeque<T>,LinkedList<T>HashMap<K, V>,BTreeMap<K, V>HashSet<T>,BTreeSet<T>BinaryHeap<T>- and any tuples
(T₁, T₂, …, Tₙ)up to length 12
T, K, and V must additionally implement Serializable.
While usize and isize also implement the trait, they are designed to panic with a message explaining why.