I have the following two variables: s
, which has type Option<&[u8; 32]>
and k
, which has type &[u8; 32]
. I would like to concatenate s
and k
into a byte array [u8; 64] using the chain
method (I'm using chain
instead of concat
because I've read it is much better performance wise), however, it seems I'm doing something wrong.
Here is a simplified example of what I'm trying to do:
fn combine(s: Option<&[u8; 32]>, k : &[u8; 32]) -> [u8; 64]{
let tmps = *s.unwrap();
let tmpk = *k;
let result = tmps.iter().chain(tmpk.iter()).collect();
result
}
fn main() {
let s = [47u8; 32];
let k = [23u8; 32];
println!("s: {:?}", s);
println!("k: {:?}", k);
let sk = combine(Some(s), k);
println!("sk: {:?}", sk);
}
The error I'm getting: a value of type '[u8; 64]' cannot be built from an iterator over elements of type '&u8'
Here is the link to Rust Playground with the code above.