Skip to content

Commit

Permalink
Add From<String> constructor for Category
Browse files Browse the repository at this point in the history
This is an alternative to the `Default::default()` constructor. The
`Default::default()` constructor produces an empty string for the
`name`, which is probably not what the user wants in most cases.

This PR also adds a similar `From<&str>` constructor.
  • Loading branch information
Jörn Bethune committed Jul 27, 2024
1 parent 23165e8 commit 0c0e6c3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,21 @@ impl ToXml for Category {
}
}

impl From<String> for Category {
fn from(name: String) -> Self {
Self { name, domain: None }
}
}

impl From<&str> for Category {
fn from(name: &str) -> Self {
Self {
name: name.to_string(),
domain: None,
}
}
}

#[cfg(feature = "builders")]
impl CategoryBuilder {
/// Builds a new `Category`.
Expand Down

0 comments on commit 0c0e6c3

Please sign in to comment.