Skip to content

Composing structs with top level attributes #567

Closed Answered by sharksforarms
DevonKS asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @DevonKS , we have an example of this pattern here: https://docs.rs/deku/latest/deku/attributes/index.html#endian

// Note: The endian is passed as a context argument to sub-types

// Example:

#[deku(endian = "endian", ctx = "endian: deku::ctx::Endian")] // context passed from `DekuTest` top-level endian
struct Child {
    field_a: u16
}

#[deku(endian = "little")] // top-level, defaults to system endianness
struct DekuTest {
    #[deku(endian = "big")] // field-level override
    field_be: u16,
    field_default: u16, // defaults to top-level

    // because a top-level endian is specified,
    // it is passed as a context
    field_child: Child,
}

let data: &[u8] = &[0xAB, 0xCD, 0xAB, 

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@DevonKS
Comment options

Answer selected by DevonKS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants