Streamline some implementations
All checks were successful
Cargo CI / Build and Test (pull_request) Successful in 1m2s
Cargo CI / Lint (pull_request) Successful in 42s

This commit is contained in:
Wojciech Kozlowski 2024-02-09 19:29:13 +01:00
parent d1d991cec7
commit 40bcd6b29d

View File

@ -117,11 +117,8 @@ impl Artist {
} }
pub fn remove_from_property<S: AsRef<str>>(&mut self, property: S, values: Vec<S>) { pub fn remove_from_property<S: AsRef<str>>(&mut self, property: S, values: Vec<S>) {
let container = self.properties.get_mut(property.as_ref()).map(|container| { if let Some(container) = self.properties.get_mut(property.as_ref()) {
container.retain(|val| !values.iter().any(|x| x.as_ref() == val)); container.retain(|val| !values.iter().any(|x| x.as_ref() == val));
container
});
if let Some(container) = container {
if container.is_empty() { if container.is_empty() {
self.properties.remove(property.as_ref()); self.properties.remove(property.as_ref());
} }
@ -129,17 +126,10 @@ impl Artist {
} }
pub fn set_property<S: AsRef<str> + Into<String>>(&mut self, property: S, values: Vec<S>) { pub fn set_property<S: AsRef<str> + Into<String>>(&mut self, property: S, values: Vec<S>) {
let mut values = values.into_iter().map(|s| s.into()).collect(); self.properties.insert(
property.into(),
match self.properties.get_mut(property.as_ref()) { values.into_iter().map(|s| s.into()).collect(),
Some(container) => { );
container.clear();
container.append(&mut values);
}
None => {
self.properties.insert(property.into(), values);
}
}
} }
pub fn clear_property<S: AsRef<str>>(&mut self, property: S) { pub fn clear_property<S: AsRef<str>>(&mut self, property: S) {