Add `try_vector` macro for initialization of a `Vector` with fallible data collection types
Closed this issue · 0 comments
chrissimpkins commented
This approach will take a single data collection argument type that is supported by the Vector
TryFrom
trait implementations. These are data collection types that may not have known length at compile time.
The approach with a std lib Vec
type will be:
let stdlib_vec = vec![1, 2, 3];
let v: Vector<i32, 3> = try_vector!(stdlib_vec).unwrap();
The macro will return an error when the std lib Vec
length differs from the requested Vector
length:
let stdlib_vec = vec![1, 2, 3, 4, 5];
// expected length 3, received length 5
let res: Result<Vector<i32, 3>, _> = try_vector!(stdlib_vec);
assert!(res.is_err());