Is there a good way to convert a Vec<T>
with size S
to an array of type [T; S]
? Specifically, I'm using a function that returns a 128-bit hash as a Vec<u8>
, which will always have length 16, and I would like to deal with the hash as a [u8, 16]
.
Is there something built-in akin to the as_slice
method which gives me what I want, or should I write my own function which allocates a fixed-size array, iterates through the vector copying each element, and returns the array?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…