Add paths() convenience iter on Event

This commit is contained in:
Félix Saparelli 2021-08-22 22:06:12 +12:00
parent 8998c40746
commit 613fe24c64
No known key found for this signature in database
GPG Key ID: B948C4BAE44FC474
1 changed files with 14 additions and 1 deletions

View File

@ -6,7 +6,10 @@
//! 2. To be filtered upon according to whatever set of criteria is desired;
//! 3. To carry information about what caused the event, which may be provided to the process.
use std::{collections::HashMap, path::PathBuf};
use std::{
collections::HashMap,
path::{Path, PathBuf},
};
use crate::signal::Signal;
@ -37,3 +40,13 @@ pub enum Source {
Os,
Time,
}
impl Event {
/// Return all paths in the event's particulars.
pub fn paths(&self) -> impl Iterator<Item = &Path> {
self.particulars.iter().filter_map(|p| match p {
Particle::Path(p) => Some(p.as_path()),
_ => None,
})
}
}