simplify logic

This commit is contained in:
yggverse 2026-03-28 06:42:24 +02:00
parent 96b9646c8c
commit a77bc468b6

View file

@ -26,26 +26,24 @@ impl Rules {
/// Reload rule set by alias from it source /// Reload rule set by alias from it source
/// * `None` to reload all /// * `None` to reload all
pub async fn reload(&mut self, list_alias: Option<&str>) -> Result<Vec<String>> { pub async fn reload(&mut self, list_alias: Option<&str>) -> Result<Vec<String>> {
let mut affected = Vec::with_capacity(if list_alias.is_some() { Ok(match list_alias {
1
} else {
self.0.len()
});
match list_alias {
Some(alias) => { Some(alias) => {
let mut affected = Vec::with_capacity(1);
if let Some(list) = self.0.get_mut(alias) { if let Some(list) = self.0.get_mut(alias) {
list.reload().await?; list.reload().await?;
affected.push(alias.into()); affected.push(alias.into());
} }
affected
} }
None => { None => {
let mut affected = Vec::with_capacity(self.0.len());
for (alias, list) in self.0.iter_mut() { for (alias, list) in self.0.iter_mut() {
list.reload().await?; list.reload().await?;
affected.push(alias.into()); affected.push(alias.into());
} }
affected
} }
} })
Ok(affected)
} }
/// Check if rule is exist in the index /// Check if rule is exist in the index
pub fn any(&self, value: &str) -> bool { pub fn any(&self, value: &str) -> bool {