Skip to content

Commit

Permalink
refactor(code): earlier return if "fields" is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
hasezoey committed Oct 1, 2023
1 parent a7aa3f4 commit ee79ee7
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ impl<'a> Struct<'a> {
.join(" ");

let fields = self.fields();

if fields.is_empty() {
self.has_fields = Some(false);
self.rendered_code = None;
return;
}

let mut lines = vec![];
for f in fields.iter() {
let field_name = &f.name;
Expand Down Expand Up @@ -277,13 +284,8 @@ impl<'a> Struct<'a> {
lines = lines.join("\n"),
);

if fields.is_empty() {
self.has_fields = Some(false);
self.rendered_code = None;
} else {
self.has_fields = Some(true);
self.rendered_code = Some(struct_code);
}
self.has_fields = Some(true);
self.rendered_code = Some(struct_code);
}
}

Expand Down

0 comments on commit ee79ee7

Please sign in to comment.