diff --git a/src/bin/main.rs b/src/bin/main.rs index 731cad8e..03a8b72d 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -136,6 +136,10 @@ pub struct MainOptions { /// See `crate::GenerationConfig::diesel_backend` for more details. #[arg(short = 'b', long = "diesel-backend")] pub diesel_backend: String, + + /// Add these additional derives to each generated `struct` + #[arg(short = 'd', long = "derive")] + pub additional_derives: Vec, } #[derive(Debug, ValueEnum, Clone, PartialEq, Default)] @@ -265,6 +269,7 @@ fn actual_main() -> dsync::Result<()> { once_connection_type: args.once_connection_type, readonly_prefixes: args.readonly_prefixes, readonly_suffixes: args.readonly_suffixes, + additional_derives: args.additional_derives, }, }, )?; diff --git a/src/code.rs b/src/code.rs index 44629b74..6b1d8267 100644 --- a/src/code.rs +++ b/src/code.rs @@ -193,7 +193,17 @@ impl<'a> Struct<'a> { /// Assemble the `derive` attribute for the struct fn attr_derive(&self) -> String { - let mut derives_vec = Vec::with_capacity(10); + let mut derives_vec = + Vec::<&str>::with_capacity(10 + self.config.options.additional_derives.len()); + if !self.config.options.additional_derives.is_empty() { + derives_vec.extend( + self.config + .options + .additional_derives + .iter() + .map(|s| -> &str { s.as_ref() }), + ); + } // Default derives that exist on every struct derives_vec.extend_from_slice(&[derives::DEBUG, derives::CLONE]); diff --git a/src/global.rs b/src/global.rs index 9ce6ec7e..06da255e 100644 --- a/src/global.rs +++ b/src/global.rs @@ -328,6 +328,9 @@ pub struct GenerationConfigOpts<'a> { pub readonly_prefixes: Vec, /// Suffixes to treat tables as readonly pub readonly_suffixes: Vec, + + /// Add these additional derives to each generated `struct` + pub additional_derives: Vec, } impl GenerationConfigOpts<'_> { @@ -363,6 +366,7 @@ impl Default for GenerationConfigOpts<'_> { once_connection_type: false, readonly_prefixes: Vec::default(), readonly_suffixes: Vec::default(), + additional_derives: Vec::default(), } } }