You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As background, I'm trying to use Deku as an optional dependency by leveraging #[cfg_attr(feature = "deku", derive(DekuRead))] to toggle Deku's functionality.
This leads to failures when trying to use deku_derive when temp fields are present, as in #[cfg_attr(feature = "deku", deku_derive(DekuRead))]
Using the snippets below, a cargo check (Deku disabled) will complete without issues.
Running cargo check --features deku will fail on Baz, stating cannot find attribute deku in scope and error[E0277]: the trait bound Vec: deku::DekuRead<'_, Endian> is not satisfied.
#[cfg(feature = "deku")]use deku::prelude::*;// Using deku_derive with cfg_attr fails#[cfg_attr(feature = "deku", deku_derive(DekuRead))]#[cfg_attr(feature = "deku", deku(endian = "big"))]structBaz{#[cfg_attr(feature = "deku", deku(temp))]length:u16,#[cfg_attr(feature = "deku", deku(count = "length"))]payload:Vec<u16>}// Conditional compilation works with regular derive.#[cfg_attr(feature = "deku", derive(DekuRead))]#[cfg_attr(feature = "deku", deku(endian = "big"))]structBar{length:u16,#[cfg_attr(feature = "deku", deku(count = "length"))]payload:Vec<u16>}// Using deku_derive without conditional compilation works as documented.// #[deku_derive(DekuRead)]// #[deku(endian = "big")]// struct Foo {// #[deku(temp)]// length: u16,// #[deku(count = "length")]// payload: Vec<u16>// }fnmain(){}
Workaround: Manually duplicate affected structs, strip Deku attributes, and conditionally compile with #[cfg(feature = "deku")] and #[cfg(not(feature = "deku"))].
#[cfg(feature = "deku")]use deku::prelude::*;// Using deku_derive to remove a temp field works as documented#[cfg(feature = "deku")]#[deku_derive(DekuRead)]#[deku(endian = "big")]structFoo{#[deku(temp)]length:u16,#[deku(count = "length")]payload:Vec<u16>}#[cfg(not(feature = "deku"))]structFoo{length:u16,payload:Vec<u16>}
The text was updated successfully, but these errors were encountered:
As background, I'm trying to use Deku as an optional dependency by leveraging
#[cfg_attr(feature = "deku", derive(DekuRead))]
to toggle Deku's functionality.This leads to failures when trying to use
deku_derive
when temp fields are present, as in#[cfg_attr(feature = "deku", deku_derive(DekuRead))]
Using the snippets below, a
cargo check
(Deku disabled) will complete without issues.Running
cargo check --features deku
will fail onBaz
, statingcannot find attribute deku in scope
anderror[E0277]: the trait bound
Vec: deku::DekuRead<'_, Endian>is not satisfied
.Cargo.toml - deku disabled by default:
src/main.rs - optional deku support:
Workaround: Manually duplicate affected structs, strip Deku attributes, and conditionally compile with
#[cfg(feature = "deku")]
and#[cfg(not(feature = "deku"))]
.The text was updated successfully, but these errors were encountered: