Skip to content

Commit b07fb7b

Browse files
committed
[src/{bin/main,global}.rs] Use vec over option
1 parent 998f4d7 commit b07fb7b

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/bin/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ fn actual_main() -> dsync::Result<()> {
269269
once_connection_type: args.once_connection_type,
270270
readonly_prefixes: args.readonly_prefixes,
271271
readonly_suffixes: args.readonly_suffixes,
272-
additional_derives: args.additional_derives,
272+
additional_derives: args.additional_derives.unwrap_or(Default::default()),
273273
},
274274
},
275275
)?;

src/code.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,19 @@ impl<'a> Struct<'a> {
193193

194194
/// Assemble the `derive` attribute for the struct
195195
fn attr_derive(&self) -> String {
196-
let mut derives_vec = match &self.config.options.additional_derives {
197-
Some(v) => {
198-
let mut _derives_vec = Vec::<&str>::with_capacity(10 + v.len());
199-
_derives_vec.extend(v.iter().map(|s| -> &str { s.as_ref() }));
200-
_derives_vec
201-
}
202-
None => Vec::with_capacity(10),
196+
let mut derives_vec = if self.config.options.additional_derives.is_empty() {
197+
Vec::with_capacity(10)
198+
} else {
199+
let mut _derives_vec =
200+
Vec::<&str>::with_capacity(10 + self.config.options.additional_derives.len());
201+
_derives_vec.extend(
202+
self.config
203+
.options
204+
.additional_derives
205+
.iter()
206+
.map(|s| -> &str { s.as_ref() }),
207+
);
208+
_derives_vec
203209
};
204210
// Default derives that exist on every struct
205211
derives_vec.extend_from_slice(&[derives::DEBUG, derives::CLONE]);

src/global.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ pub struct GenerationConfigOpts<'a> {
330330
pub readonly_suffixes: Vec<String>,
331331

332332
/// Add these additional derives to each generated `struct`
333-
pub additional_derives: Option<Vec<String>>,
333+
pub additional_derives: Vec<String>,
334334
}
335335

336336
impl GenerationConfigOpts<'_> {
@@ -366,7 +366,7 @@ impl Default for GenerationConfigOpts<'_> {
366366
once_connection_type: false,
367367
readonly_prefixes: Vec::default(),
368368
readonly_suffixes: Vec::default(),
369-
additional_derives: None,
369+
additional_derives: Vec::default(),
370370
}
371371
}
372372
}

0 commit comments

Comments
 (0)