mirror of
https://github.com/watchexec/watchexec.git
synced 2024-09-29 22:51:33 +02:00
Move filter types out
This commit is contained in:
parent
2be21b6bac
commit
29d0b66ba9
@ -1,61 +1,5 @@
|
|||||||
use std::{collections::HashSet, path::PathBuf};
|
#[doc(inline)]
|
||||||
|
pub use types::*;
|
||||||
use globset::Glob;
|
|
||||||
use regex::Regex;
|
|
||||||
|
|
||||||
mod parse;
|
mod parse;
|
||||||
|
mod types;
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
||||||
pub struct Filter {
|
|
||||||
pub in_path: Option<PathBuf>,
|
|
||||||
pub on: Matcher,
|
|
||||||
pub op: Op,
|
|
||||||
pub pat: Pattern,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
||||||
#[non_exhaustive]
|
|
||||||
pub enum Matcher {
|
|
||||||
Tag,
|
|
||||||
Path,
|
|
||||||
FileEventKind,
|
|
||||||
Source,
|
|
||||||
Process,
|
|
||||||
Signal,
|
|
||||||
ProcessCompletion,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
||||||
#[non_exhaustive]
|
|
||||||
pub enum Op {
|
|
||||||
Auto, // =
|
|
||||||
Equal, // ==
|
|
||||||
NotEqual, // !=
|
|
||||||
Regex, // ~=
|
|
||||||
Glob, // *=
|
|
||||||
InSet, // :=
|
|
||||||
NotInSet, // :!
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
#[non_exhaustive]
|
|
||||||
pub enum Pattern {
|
|
||||||
Exact(String),
|
|
||||||
Regex(Regex),
|
|
||||||
Glob(Glob),
|
|
||||||
Set(HashSet<String>),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PartialEq<Self> for Pattern {
|
|
||||||
fn eq(&self, other: &Self) -> bool {
|
|
||||||
match (self, other) {
|
|
||||||
(Self::Exact(l), Self::Exact(r)) => l == r,
|
|
||||||
(Self::Regex(l), Self::Regex(r)) => l.as_str() == r.as_str(),
|
|
||||||
(Self::Glob(l), Self::Glob(r)) => l == r,
|
|
||||||
(Self::Set(l), Self::Set(r)) => l == r,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Eq for Pattern {}
|
|
||||||
|
59
lib/src/filter/types.rs
Normal file
59
lib/src/filter/types.rs
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
use std::{collections::HashSet, path::PathBuf};
|
||||||
|
|
||||||
|
use globset::Glob;
|
||||||
|
use regex::Regex;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct Filter {
|
||||||
|
pub in_path: Option<PathBuf>,
|
||||||
|
pub on: Matcher,
|
||||||
|
pub op: Op,
|
||||||
|
pub pat: Pattern,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
|
#[non_exhaustive]
|
||||||
|
pub enum Matcher {
|
||||||
|
Tag,
|
||||||
|
Path,
|
||||||
|
FileEventKind,
|
||||||
|
Source,
|
||||||
|
Process,
|
||||||
|
Signal,
|
||||||
|
ProcessCompletion,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
|
pub enum Op {
|
||||||
|
Auto, // =
|
||||||
|
Equal, // ==
|
||||||
|
NotEqual, // !=
|
||||||
|
Regex, // ~=
|
||||||
|
Glob, // *=
|
||||||
|
InSet, // :=
|
||||||
|
NotInSet, // :!
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
#[non_exhaustive]
|
||||||
|
pub enum Pattern {
|
||||||
|
Exact(String),
|
||||||
|
Regex(Regex),
|
||||||
|
Glob(Glob),
|
||||||
|
Set(HashSet<String>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialEq<Self> for Pattern {
|
||||||
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
match (self, other) {
|
||||||
|
(Self::Exact(l), Self::Exact(r)) => l == r,
|
||||||
|
(Self::Regex(l), Self::Regex(r)) => l.as_str() == r.as_str(),
|
||||||
|
(Self::Glob(l), Self::Glob(r)) => l == r,
|
||||||
|
(Self::Set(l), Self::Set(r)) => l == r,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Eq for Pattern {}
|
Loading…
Reference in New Issue
Block a user