This is probably a question that has been asked many times, sorry about that.
I want to make a function that creates a byte array and returns a slice to it, and use only lifetimes.
I don’t care how the byte array is created but it needs an initial size, and it will be mutated by a function that receives a unsized array. The function should return an unsized array (because in practice I do not know what is the size of the array at the start of the functions
fn create_new_byte_array(v :&[u8]) -> Result<&[u8], io::Error> {
const N: usize = 1500;
//let mut result: Vec<u8> = Vec::<_>::with_capacity(N);
let mut result: [u8; N] = [0; N];
// builder.write(&mut result.as_mut_slice(), v); // some byte transform
return Ok(&result.as_slice());
}
How can this be done in a Rust manner? Any tips about other details are welcome for a noob.
1