I have an &[u8]
and would like to turn it into an &[u8; 3]
without copying. It should reference the original array. How can I do this?
相关问题
- How to get the maximum of more than 2 numbers in V
- Faster loop: foreach vs some (performance of jsper
- Convert Array to custom object list c#
- pick a random item from a javascript array
- Newtonsoft DeserializeXNode expands internal array
相关文章
- How can I convert a f64 to f32 and get the closest
- Numpy matrix of coordinates
- What is a good way of cleaning up after a unit tes
- PHP: Can an array have an array as a key in a key-
- Accessing an array element when returning from a f
- How can I convert a PHP function's parameter l
- How to make a custom list deserializer in Gson?
- Recursively replace keys in an array
They arrayref crate implements this.
Here's an example, you can of course use it in different ways:
As of Rust 1.34, you can use
TryFrom
/TryInto
:Just to re-emphasize, this can't be done without unsafe code because you don't know until runtime that the slice has three elements in it.
This can't be generic over the length of the array until const generics are implemented.