diff --git a/src/metadata/file.rs b/src/metadata/file.rs index 4556a0b0..13693736 100644 --- a/src/metadata/file.rs +++ b/src/metadata/file.rs @@ -38,14 +38,14 @@ impl File { /// CommonMark. #[must_use] pub fn with_display_name(mut self, display_name: String) -> Self { - self.display_name = Some(display_name); + self.set_display_name(display_name); self } /// Set the condition string. #[must_use] pub fn with_condition(mut self, condition: String) -> Self { - self.condition = Some(condition); + self.set_condition(condition); self } @@ -56,8 +56,7 @@ impl File { mut self, detail: Vec, ) -> Result { - validate_message_contents(&detail)?; - self.detail = detail; + self.set_detail(detail)?; Ok(self) } @@ -71,6 +70,13 @@ impl File { self.display_name.as_deref() } + /// Set the name to be displayed for the file in messages, formatted using + /// CommonMark. + pub fn set_display_name(&mut self, display_name: String) -> &mut Self { + self.display_name = Some(display_name); + self + } + /// Get the detail message content of the file. /// /// If this file causes an error message to be displayed, the detail message @@ -80,10 +86,28 @@ impl File { &self.detail } + /// Set the detail message content, which may be appended to any messages + /// generated for this file. If multilingual, one language must be + /// [MessageContent::DEFAULT_LANGUAGE]. + pub fn set_detail( + &mut self, + detail: Vec, + ) -> Result<&mut Self, MultilingualMessageContentsError> { + validate_message_contents(&detail)?; + self.detail = detail; + Ok(self) + } + /// Get the condition string. pub fn condition(&self) -> Option<&str> { self.condition.as_deref() } + + /// Set the condition string. + pub fn set_condition(&mut self, condition: String) -> &mut Self { + self.condition = Some(condition); + self + } } /// Represents a case-insensitive filename. diff --git a/src/metadata/group.rs b/src/metadata/group.rs index 104b5b76..f976e71d 100644 --- a/src/metadata/group.rs +++ b/src/metadata/group.rs @@ -27,14 +27,14 @@ impl Group { /// Set a description for the group. #[must_use] pub fn with_description(mut self, description: String) -> Self { - self.description = Some(description); + self.set_description(description); self } /// Set the names of the groups that this group loads after. #[must_use] pub fn with_after_groups(mut self, after_groups: Vec) -> Self { - self.after_groups = after_groups; + self.set_after_groups(after_groups); self } @@ -51,10 +51,22 @@ impl Group { self.description.as_deref() } + /// Set a description for the group. + pub fn set_description(&mut self, description: String) -> &mut Self { + self.description = Some(description); + self + } + /// Get the names of the groups that this group loads after. pub fn after_groups(&self) -> &[String] { &self.after_groups } + + /// Set the names of the groups that this group loads after. + pub fn set_after_groups(&mut self, after_groups: Vec) -> &mut Self { + self.after_groups = after_groups; + self + } } impl std::default::Default for Group { diff --git a/src/metadata/location.rs b/src/metadata/location.rs index 66872672..ae7eb639 100644 --- a/src/metadata/location.rs +++ b/src/metadata/location.rs @@ -27,7 +27,7 @@ impl Location { /// Set a name for the URL, eg. the page or site name. #[must_use] pub fn with_name(mut self, name: String) -> Self { - self.name = Some(name); + self.set_name(name); self } @@ -40,6 +40,12 @@ impl Location { pub fn name(&self) -> Option<&str> { self.name.as_deref() } + + /// Set a name for the URL, eg. the page or site name. + pub fn set_name(&mut self, name: String) -> &mut Self { + self.name = Some(name); + self + } } impl TryFrom<&MarkedYaml> for Location { diff --git a/src/metadata/message.rs b/src/metadata/message.rs index 1c31868c..594be6f5 100644 --- a/src/metadata/message.rs +++ b/src/metadata/message.rs @@ -65,7 +65,7 @@ impl MessageContent { /// Set the language code to the given value. #[must_use] pub fn with_language(mut self, language: String) -> Self { - self.language = language; + self.set_language(language); self } @@ -78,6 +78,12 @@ impl MessageContent { pub fn language(&self) -> &str { &self.language } + + /// Set the language code to the given value. + pub fn set_language(&mut self, language: String) -> &mut Self { + self.language = language; + self + } } impl std::default::Default for MessageContent { @@ -194,7 +200,7 @@ impl Message { /// Set the condition string. #[must_use] pub fn with_condition(mut self, condition: String) -> Self { - self.condition = Some(condition); + self.set_condition(condition); self } @@ -212,6 +218,12 @@ impl Message { pub fn condition(&self) -> Option<&str> { self.condition.as_deref() } + + /// Set the condition string. + pub fn set_condition(&mut self, condition: String) -> &mut Self { + self.condition = Some(condition); + self + } } pub(crate) fn validate_message_contents( diff --git a/src/metadata/plugin_cleaning_data.rs b/src/metadata/plugin_cleaning_data.rs index db990fc2..550a077e 100644 --- a/src/metadata/plugin_cleaning_data.rs +++ b/src/metadata/plugin_cleaning_data.rs @@ -38,21 +38,21 @@ impl PluginCleaningData { /// Set the number of Identical To Master records found in the plugin. #[must_use] pub fn with_itm_count(mut self, itm_count: u32) -> Self { - self.itm_count = itm_count; + self.set_itm_count(itm_count); self } /// Set the number of deleted references found in the plugin. #[must_use] pub fn with_deleted_reference_count(mut self, deleted_reference_count: u32) -> Self { - self.deleted_reference_count = deleted_reference_count; + self.set_deleted_reference_count(deleted_reference_count); self } /// Set the number of deleted navmeshes found in the plugin. #[must_use] pub fn with_deleted_navmesh_count(mut self, deleted_navmesh_count: u32) -> Self { - self.deleted_navmesh_count = deleted_navmesh_count; + self.set_deleted_navmesh_count(deleted_navmesh_count); self } @@ -63,8 +63,7 @@ impl PluginCleaningData { mut self, detail: Vec, ) -> Result { - validate_message_contents(&detail)?; - self.detail = detail; + self.set_detail(detail)?; Ok(self) } @@ -78,16 +77,34 @@ impl PluginCleaningData { self.itm_count } + /// Set the number of Identical To Master records found in the plugin. + pub fn set_itm_count(&mut self, itm_count: u32) -> &mut Self { + self.itm_count = itm_count; + self + } + /// Get the number of deleted references found in the plugin. pub fn deleted_reference_count(&self) -> u32 { self.deleted_reference_count } + /// Set the number of deleted references found in the plugin. + pub fn set_deleted_reference_count(&mut self, deleted_reference_count: u32) -> &mut Self { + self.deleted_reference_count = deleted_reference_count; + self + } + /// Get the number of deleted navmeshes found in the plugin. pub fn deleted_navmesh_count(&self) -> u32 { self.deleted_navmesh_count } + /// Set the number of deleted navmeshes found in the plugin. + pub fn set_deleted_navmesh_count(&mut self, deleted_navmesh_count: u32) -> &mut Self { + self.deleted_navmesh_count = deleted_navmesh_count; + self + } + /// Get the cleaning utility that was used to check the plugin. /// /// The string may include a cleaning utility name, possibly related @@ -103,6 +120,18 @@ impl PluginCleaningData { pub fn detail(&self) -> &[MessageContent] { &self.detail } + + /// Set the detail message content, which may be appended to any messages + /// generated for this cleaning data. If multilingual, one language must be + /// [MessageContent::DEFAULT_LANGUAGE]. + pub fn set_detail( + &mut self, + detail: Vec, + ) -> Result<&mut Self, MultilingualMessageContentsError> { + validate_message_contents(&detail)?; + self.detail = detail; + Ok(self) + } } impl TryFrom<&MarkedYaml> for PluginCleaningData { diff --git a/src/metadata/tag.rs b/src/metadata/tag.rs index e6fcbf0e..d63a6b84 100644 --- a/src/metadata/tag.rs +++ b/src/metadata/tag.rs @@ -54,6 +54,12 @@ impl Tag { pub fn condition(&self) -> Option<&str> { self.condition.as_deref() } + + /// Set the condition string. + pub fn set_condition(&mut self, condition: String) -> &mut Self { + self.condition = Some(condition); + self + } } impl TryFrom<&saphyr::MarkedYaml> for Tag { diff --git a/src/sorting/vertex.rs b/src/sorting/vertex.rs index 0c4b8f38..0b96ae33 100644 --- a/src/sorting/vertex.rs +++ b/src/sorting/vertex.rs @@ -59,7 +59,7 @@ impl Vertex { /// Set the type of the edge going from this vertex to the next in the path. #[must_use] pub fn with_out_edge_type(mut self, out_edge_type: EdgeType) -> Self { - self.out_edge_type = Some(out_edge_type); + self.set_out_edge_type(out_edge_type); self } @@ -72,4 +72,10 @@ impl Vertex { pub fn out_edge_type(&self) -> Option { self.out_edge_type } + + /// Set the type of the edge going from this vertex to the next in the path. + pub fn set_out_edge_type(&mut self, out_edge_type: EdgeType) -> &mut Self { + self.out_edge_type = Some(out_edge_type); + self + } }