rename some members; add documentation

This commit is contained in:
postscriptum 2026-03-23 09:05:05 +02:00
parent eeafed077a
commit 8586a5b036
3 changed files with 12 additions and 5 deletions

View file

@ -16,6 +16,7 @@ pub struct List {
}
impl List {
/// Build new List object
pub async fn from_opt(list: &Vec<String>, cache: Option<PathBuf>) -> Result<Self> {
fn handle(this: &mut HashSet<Item>, line: &str) -> Option<bool> {
if line.starts_with("/") || line.starts_with("#") || line.is_empty() {
@ -73,19 +74,25 @@ impl List {
cache,
})
}
/// Check if rule is exist in the (allow) index
pub async fn any(&self, value: &str) -> bool {
self.index.read().await.iter().any(|item| match item {
Item::Exact(v) => v == value,
Item::Ending(v) => value.ends_with(v),
})
}
pub async fn entries(&self) -> u64 {
/// Get total rules from the current session
pub async fn rules(&self) -> u64 {
self.index.read().await.len() as u64
}
/// Allow given `rule`
/// * return `false` if the `rule` is exist
pub async fn allow(&self, rule: &str) -> Result<bool> {
self.cache.allow(rule).await?;
Ok(self.index.write().await.insert(Item::from_line(rule)))
}
/// Block given `rule`
/// * return `false` if the `rule` is not exist
pub async fn block(&self, rule: &str) -> Result<bool> {
self.cache.block(rule).await?;
Ok(self.index.write().await.remove(&Item::from_line(rule)))