Hi I am trying to create more advanced structure where I embedded bitfield struct inside regular struct but I am struggling with structure creation.
To illustrate my problem I provide example code:
I have two bitfields: Header and DW1. Header is 8 bits, DoubleWorld is 32 bits.
Both structures create Request structure, which under the hood use them.
error[E0271]: type mismatch resolving `<[u8; 5] as Index<std::ops::Range<usize>>>::Output == [u8; 5]`
--> src/main.rs:55:16
|
38 | pub fn new(bytes: T) -> Request<T> {
| ---------------------------------- required by `Request::<T>::new`
...
55 | let request = Request::new(bytes); // expected array `[u8; 5]`, found slice?
| ^^^^^^^^^^^^ expected array `[u8; 5]`, found slice
|
= note: expected array `[u8; 5]`
found slice `[u8]`
error: aborting due to previous error; 1 warning emitted
Compiler suggest that I am providing wrong argument to the Request::new() method (It expects array but Slice is provided).
I am not entirely sure if that is just a matter of provided argument.
Bytes is [u8; 5] array not a slice. I also tried few things like using slice_as_array create but any changes to Request::new method is causing issue with Generic passed to the other bitfields.
At that point I am thinking that probably I am designing my code in bad way, so was curious if there are any examples or tips how to create structures based on other bitfields based structures?
Appreciate any help!
Hi I am trying to create more advanced structure where I embedded bitfield struct inside regular struct but I am struggling with structure creation.
To illustrate my problem I provide example code: I have two bitfields: Header and DW1. Header is 8 bits, DoubleWorld is 32 bits. Both structures create Request structure, which under the hood use them.
When I try to use that I got followed error:
Compiler suggest that I am providing wrong argument to the
Request::new()
method (It expects array but Slice is provided). I am not entirely sure if that is just a matter of provided argument.Bytes is [u8; 5] array not a slice. I also tried few things like using
slice_as_array
create but any changes toRequest::new
method is causing issue with Generic passed to the otherbitfields
.At that point I am thinking that probably I am designing my code in bad way, so was curious if there are any examples or tips how to create structures based on other bitfields based structures? Appreciate any help!