Streamline some implementations
This commit is contained in:
parent
d1d991cec7
commit
40bcd6b29d
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user