I have this code in C that writes in a fd the command. My issue is that I can't represent the same behaviour in Rust language because apparently the .write()
doesn't takes the same parameters as C's write()
. The function is the following:
static void set_address(int32_t fd, uint64_t start_address, uint64_t len){
uint64_t command[3];
int64_t bytes;
command[0] = SET_ADDRESS_AREA;
command[1] = start_address;
command[2] = len;
bytes = write(fd, command, (ssize_t)LEN_SET_ADDRESS_AREA);
if (bytes != LEN_SET_ADDRESS_AREA)
{
printf("\nError\n");
exit(-1);
}
}
So my code is:
for (i,val) in ref_memory.iter().enumerate().step_by(DIM_SLICE){
let mut start_address = val ;
let p = std::ptr::addr_of!(start_address);
println!("the address index of val is {:?}",p);
let mut command = (SET_ADDRESS_AREA,start_address,DIM_SLICE);
let file_buffer = File::create(_path);
let bytes_written = file_buffer.unwrap().write(command);
}
}
Writing this
let bytes_written = file_buffer.unwrap().write(command);
I get the error:
Mismatched types: expected reference &[u8] and found tuple (u8, &u8, u8)
Should I create a struct to pass just one reference of type &u8?
Alternatively, is there a crate that offers this feature?