Expand description
Types to help compose fixed-size ULE
and variable-size VarULE
primitives.
This module exports VarTuple
and VarTupleULE
, which allow a single sized type and
a single unsized type to be stored together as a VarULE
.
§Examples
use zerovec::ule::vartuple::{VarTuple, VarTupleULE};
use zerovec::VarZeroVec;
struct Employee<'a> {
id: u32,
name: &'a str,
};
let employees = [
Employee {
id: 12345,
name: "Jane Doe",
},
Employee {
id: 67890,
name: "John Doe",
},
];
let employees_as_var_tuples = employees
.into_iter()
.map(|x| VarTuple {
sized: x.id,
variable: x.name,
})
.collect::<Vec<_>>();
let employees_vzv: VarZeroVec<VarTupleULE<u32, str>> =
employees_as_var_tuples.as_slice().into();
assert_eq!(employees_vzv.len(), 2);
assert_eq!(employees_vzv.get(0).unwrap().sized.as_unsigned_int(), 12345);
assert_eq!(&employees_vzv.get(0).unwrap().variable, "Jane Doe");
assert_eq!(employees_vzv.get(1).unwrap().sized.as_unsigned_int(), 67890);
assert_eq!(&employees_vzv.get(1).unwrap().variable, "John Doe");
Structs§
- A sized type that can be converted to a
VarTupleULE
. - A dynamically-sized type combining a sized and an unsized type.