Streamline adding new URL types #122

Merged
wojtek merged 7 commits from 117---streamline-adding-new-url-types into main 2024-02-09 18:41:21 +01:00
Showing only changes of commit 40bcd6b29d - Show all commits

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));
wojtek marked this conversation as resolved
Review

Split map from the get_mut. Will be more legible and the container variable is used later anyway.

Split map from the get_mut. Will be more legible and the container variable is used later anyway.
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) {