Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc request: update for structs #409

Open
sempervictus opened this issue Jan 20, 2024 · 0 comments
Open

Doc request: update for structs #409

sempervictus opened this issue Jan 20, 2024 · 0 comments

Comments

@sempervictus
Copy link

sempervictus commented Jan 20, 2024

#[deku(update = "another_field.some_calls_returning_new_value()")

doesn't really work for structs with multiple members when we need to perform another_field.some_calls_returning_new_value() for this.member since rust doesn't allow calls up to the parent from the struct member to be updated, a bit confused on the semantic required.

#[deku_derive(DekuRead, DekuWrite)]
#[derive(Debug, PartialEq)]
#[deku(endian = "endian", ctx = "endian: Endian")]
pub(super) struct UbString {
    #[deku(update = "self.hdr.length = self.val.len() as u16")]
    pub(super) hdr: UbHdr,
    #[deku(count = "hdr.length")]
    pub(super) val: Vec<u8>,
}

doesn't work either due to a somewhat opaque

error[E0277]: the trait bound `UbHdr: From<()>` is not satisfied
...
   |
65 | #[deku_derive(DekuRead, DekuWrite)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<()>` is not implemented for `UbHdr`
   |
   = note: required for `()` to implement `Into<UbHdr>`
   = note: required for `UbHdr` to implement `TryFrom<()>`
   = note: required for `()` to implement `TryInto<UbHdr>`
   = note: this error originates in the attribute macro `deku_derive` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0277`.

error.

Trying to do this by creating a whole new UbHdr struct in the update macro fails with the same From related error even though in neither case is there any sort of type conversion given that i'm providing the correct type to either the struct member or the entire struct replacment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant