Skip to content
2 changes: 1 addition & 1 deletion src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +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,
additional_derives: args.additional_derives.unwrap_or(Default::default()),
},
},
)?;
Expand Down
20 changes: 13 additions & 7 deletions src/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,19 @@ impl<'a> Struct<'a> {

/// Assemble the `derive` attribute for the struct
fn attr_derive(&self) -> String {
let mut derives_vec = match &self.config.options.additional_derives {
Some(v) => {
let mut _derives_vec = Vec::<&str>::with_capacity(10 + v.len());
_derives_vec.extend(v.iter().map(|s| -> &str { s.as_ref() }));
_derives_vec
}
None => Vec::with_capacity(10),
let mut derives_vec = if self.config.options.additional_derives.is_empty() {
Vec::with_capacity(10)
} else {
let mut _derives_vec =
Vec::<&str>::with_capacity(10 + self.config.options.additional_derives.len());
_derives_vec.extend(
self.config
.options
.additional_derives
.iter()
.map(|s| -> &str { s.as_ref() }),
);
_derives_vec
};
// Default derives that exist on every struct
derives_vec.extend_from_slice(&[derives::DEBUG, derives::CLONE]);
Expand Down
4 changes: 2 additions & 2 deletions src/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ pub struct GenerationConfigOpts<'a> {
pub readonly_suffixes: Vec<String>,

/// Add these additional derives to each generated `struct`
pub additional_derives: Option<Vec<String>>,
pub additional_derives: Vec<String>,
}

impl GenerationConfigOpts<'_> {
Expand Down Expand Up @@ -366,7 +366,7 @@ impl Default for GenerationConfigOpts<'_> {
once_connection_type: false,
readonly_prefixes: Vec::default(),
readonly_suffixes: Vec::default(),
additional_derives: None,
additional_derives: Vec::default(),
}
}
}
Expand Down