pub struct RuleStore { /* private fields */ }Expand description
Loader and watcher for per-machine tower rule files.
Rules live in <rules_dir>/*.yaml (or .yml / .json). The store is
stateless — call load_all at boot and watch to receive subsequent changes.
Implementations§
Source§impl RuleStore
impl RuleStore
pub fn new(rules_dir: impl Into<PathBuf>) -> Self
pub fn rules_dir(&self) -> &Path
Sourcepub fn load_all(&self) -> LoadResult
pub fn load_all(&self) -> LoadResult
Load all rule files from the rules directory.
Non-rule files (wrong extension) are silently ignored. Files that fail
parsing, validation, or version checks are collected in skipped.
I/O errors reading the directory are logged and an empty result returned.
Sourcepub fn load_file(
&self,
path: &Path,
) -> Result<(TowerRule, Vec<RuleWarning>), SkipReason>
pub fn load_file( &self, path: &Path, ) -> Result<(TowerRule, Vec<RuleWarning>), SkipReason>
Parse and validate a single rule file.
YAML and JSON are both accepted. The schema version is probed before
full deserialisation so that future-version files produce a
SkipReason::FutureVersion rather than a serde unknown-variant error.
Sourcepub fn watch(&self) -> Result<(RuleWatcher, Receiver<WatchEvent>), Error>
pub fn watch(&self) -> Result<(RuleWatcher, Receiver<WatchEvent>), Error>
Start a config-file watcher on the rules directory.
Returns a RuleWatcher handle (keep alive for as long as watching is
desired) and a mpsc::Receiver<WatchEvent> for consuming events.
The watcher translates notify events into WatchEvents on a background
thread. The thread exits when the watcher handle is dropped (channel close).