Skip to content

Commit

Permalink
Use fmt_cfg helper instead of match
Browse files Browse the repository at this point in the history
  • Loading branch information
scootermon authored Aug 27, 2024
1 parent c562af5 commit 3f69061
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,27 +149,13 @@ pub fn codegen(config: Config<'_>, out: impl Write) -> Result<()> {
writeln!(&mut w, "use bitvec::prelude::*;")?;
writeln!(&mut w, "use embedded_can::{{Id, StandardId, ExtendedId}};")?;

match config.impl_arbitrary {
FeatureConfig::Always => {
writeln!(&mut w, "use arbitrary::{{Arbitrary, Unstructured}};")?;
}
FeatureConfig::Gated(gate) => {
writeln!(w, r##"#[cfg(feature = "{gate}")]"##)?;
writeln!(&mut w, "use arbitrary::{{Arbitrary, Unstructured}};")?;
}
FeatureConfig::Never => (),
}
config.impl_arbitrary.fmt_cfg(&mut w, |w| {
writeln!(w, "use arbitrary::{{Arbitrary, Unstructured}};")
})?;

match config.impl_serde {
FeatureConfig::Always => {
writeln!(&mut w, "use serde::{{Serialize, Deserialize}};")?;
}
FeatureConfig::Gated(gate) => {
writeln!(w, r##"#[cfg(feature = "{gate}")]"##)?;
writeln!(&mut w, "use serde::{{Serialize, Deserialize}};")?;
}
FeatureConfig::Never => (),
}
config.impl_serde.fmt_cfg(&mut w, |w| {
writeln!(w, "use serde::{{Serialize, Deserialize}};")
})?;

writeln!(&mut w)?;

Expand Down

0 comments on commit 3f69061

Please sign in to comment.