In Rust, an array has its length encoded in its type – e.g., [u8; 5] – it is a compile-time property, whereas a Vec's length is a run-time property. Every byte array, [u8; N], implements TryFrom<Vec<u8>> , so Vec<u8> implements TryInto<[u8; N]> as a result. Therefore, you can use try_into() on a Vec<u8> to convert it into a byte array:
let a: [u8; 5] = v.try_into().unwrap();
Note that TryInto::try_into() returns a Result for the reason explained above: the mismatch of the nature of the length property of a Vec and an array – run-time and compile-time, respectively.
Why not convert the Vec<u8> into a byte slice instead?
Keep in mind that you can easily create a byte slice (i.e., &[u8]) from a Vec<T>. A Vec<u8> deref coerces into [u8] as it implements Deref<Target=[u8]>:
let v = b"Hello".to_vec();
let a: &[u8] = &v;
You can also call as_slice() on a Vec<u8>:
let a = v.as_slice();
This may be what you want because you are probably using a Vec to be able to change the length at run time.
vec<u8>satisfy your use case? And it's mostly not recommanded because[u8]requires an explicit static size during the compile time.