Hi, I am trying to make two function system where I take two arrays as input and give out an array as output. But, it seems like perhaps I am going wrong somewhere, which I am not able to understand correctly. Please have a look at my code.
const LEN: usize = 160;
struct MyCircuit {
/// The input to redact we are proving that we know. Set to `None` when we
/// are verifying a proof (and do not have the witness data).
preimage: Option<[u8; LEN]>,
}
struct mask {
mask: Option<[u8;LEN]>
}
fn main(){
let preimage = [42;LEN];
let mut mask = [1;LEN];
for i in (21..40){
mask[i] = 0;
}
for i in (43..51){
mask[i] = 0;
}
for i in (120..140){
mask[i] = 0;
}
println!("Preimage..");
for i in 1..LEN{
println!("{}",preimage[i]);
}
println!("Mask..");
for i in 1..LEN{
println!("{}",&mut mask[i]);
}
let mut masked_array = [0;LEN];
println!("Masked Array...");
masked_array = redact(&preimage, &mask);
for i in 1..LEN{
println!("{}", &mut masked_array[i]);
}
}
fn redact(preimage: & [u8], mask: &mut [u8] ){
let mut internal = [0;LEN];
for i in 1..LEN{
internal[i] = preimage[i]*mask[i];
}
return internal;
}
This is, essentially, redefining const LEN: usize = x;, which is a global constant without real meaning shared everywhere, to live in the type system. This allows the compiler to check that the arrays arguments for the redact_3 function have in fact the same length before the code even runs. Which in turns allows us to return a stack allocated array instead of taking a mutable array as third argument or returning a heap allocated Vec.