diff --git a/src/rust/lib_gen.rs b/src/rust/lib_gen.rs index e3638a3..75d0b10 100644 --- a/src/rust/lib_gen.rs +++ b/src/rust/lib_gen.rs @@ -32,21 +32,43 @@ impl Verbosity { } } +#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd)] +pub enum Attribute { + DenyClippy, +} + +impl Attribute { + fn code(&self) -> RustPrinter { + match self { + Attribute::DenyClippy => line(unit() + "#![deny(clippy)]"), + } + } +} + #[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd)] pub struct ModuleName { name: String, verbosity: Verbosity, + attributes: Vec, } impl ModuleName { fn code(&self) -> RustPrinter { - line(unit() + self.verbosity.render() + "mod " + escape_keywords(&self.name) + ";") + unit() + + self + .attributes + .iter() + .map(|a| a.code()) + .reduce(|acc, e| acc + line(e)) + .unwrap_or_else(unit) + + line(unit() + self.verbosity.render() + "mod " + escape_keywords(&self.name) + ";") } pub fn new>(s: S) -> ModuleName { ModuleName { name: s.into(), verbosity: Verbosity::Default, + attributes: vec![Attribute::DenyClippy], } } @@ -54,6 +76,7 @@ impl ModuleName { ModuleName { name: s.into(), verbosity: Verbosity::Pub, + attributes: vec![Attribute::DenyClippy], } } @@ -136,7 +159,9 @@ mod tests { ); let expected = indoc! { r#" + #![deny(clippy)] mod abc; + #![deny(clippy)] mod xyz; pub use lib::abc::B;