I want to create a type containing an array allocated to the stack.
struct MyStruct {
values: [u8; 25],
}
I'm not able to implement the MyStruct::new()
trait to initialize the struct's array.
Here's my unsuccessful atempt:
impl MyStruct {
fn new(numbers: &[u8]) -> Self {
Self {
values: numbers.copy_from_slice(),
}
}
}
I encountered some solutions on the internet, but they all either initialize the array to 0 or use the heap with Vec<u8>
.
I can't find anything on the internet other than "use a vector" solutions.
How do I memcpy
arrays in a safe way in rust?