Avoid using ..Default::default()

Exhaustively naming fields means I can't forget to set sensible values in cases where Default::default() might not produce them.
This commit is contained in:
Oliver Hamlet
2026-04-03 16:53:37 +01:00
parent 4574d8751a
commit fff0bdbc8a
8 changed files with 39 additions and 9 deletions
+4 -1
View File
@@ -32,7 +32,10 @@ impl File {
pub fn new(name: String) -> Self {
Self {
name: Filename::new(name),
..Default::default()
display_name: None,
detail: Box::default(),
condition: None,
constraint: None,
}
}
+2 -1
View File
@@ -25,7 +25,8 @@ impl Group {
pub fn new(name: String) -> Self {
Self {
name: name.into_boxed_str(),
..Default::default()
description: None,
after_groups: Box::default(),
}
}
+1 -1
View File
@@ -18,7 +18,7 @@ impl Location {
pub fn new(url: String) -> Self {
Location {
url: url.into_boxed_str(),
..Default::default()
name: None,
}
}
+1 -1
View File
@@ -59,7 +59,7 @@ impl MessageContent {
pub fn new(text: String) -> Self {
MessageContent {
text: text.into_boxed_str(),
..Default::default()
language: MessageContent::DEFAULT_LANGUAGE.into(),
}
}
+5 -1
View File
@@ -34,8 +34,12 @@ impl PluginCleaningData {
pub fn new(crc: u32, cleaning_utility: String) -> Self {
Self {
crc,
itm_count: 0,
deleted_reference_count: 0,
deleted_navmesh_count: 0,
cleaning_utility: cleaning_utility.into_boxed_str(),
..Default::default()
detail: Box::default(),
condition: None,
}
}
+18 -2
View File
@@ -42,14 +42,30 @@ impl PluginMetadata {
pub fn new(name: &str) -> Result<Self, RegexError> {
Ok(Self {
name: PluginName::new(name)?,
..Default::default()
group: None,
load_after: Box::default(),
requirements: Box::default(),
incompatibilities: Box::default(),
messages: Box::default(),
tags: Box::default(),
dirty_info: Box::default(),
clean_info: Box::default(),
locations: Box::default(),
})
}
pub(crate) fn with_same_name(metadata: &PluginMetadata) -> Self {
Self {
name: metadata.name.clone(),
..Default::default()
group: None,
load_after: Box::default(),
requirements: Box::default(),
incompatibilities: Box::default(),
messages: Box::default(),
tags: Box::default(),
dirty_info: Box::default(),
clean_info: Box::default(),
locations: Box::default(),
}
}
+7 -1
View File
@@ -26,7 +26,13 @@ mod test {
pub(super) fn new(name: &str) -> Self {
Self {
name: name.to_owned(),
..Default::default()
masters: Vec::new(),
is_master: false,
is_blueprint_plugin: false,
override_record_count: 0,
asset_count: 0,
overlapping_record_plugins: Vec::new(),
overlapping_asset_plugins: Vec::new(),
}
}
+1 -1
View File
@@ -52,7 +52,7 @@ impl Vertex {
pub fn new(name: String) -> Self {
Self {
name,
..Default::default()
out_edge_type: None,
}
}