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 boundVec: deku::DekuRead<'_, Endian>is not satisfied.
Cargo.toml - deku disabled by default:
[package]
name = "deku-conditional"
version = "0.1.0"
edition = "2021"
[dependencies]
deku = { version = "0.16.0", optional = true }
[features]
deku = ["dep:deku"]
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: deku::DekuRead<'_, Endian>
cargo check --features deku
will fail onBaz
, statingcannot find attribute deku in scope
anderror[E0277]: the trait bound
Vecis 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"))]
.