Struct Watcher

Source
pub struct Watcher<H: WatcherHandler> { /* private fields */ }
Expand description

A file watcher that monitors specified files for changes and notifies a handler when updates occur.

Implementations§

Source§

impl<H: WatcherHandler> Watcher<H>

Source

pub async fn new( platform: Platform, poll_interval: u64, handler: H, ) -> Result<Self, Error>

Creates a new Watcher instance that monitors configuration files for changes.

§Parameters
  • platform: The target platform for which the configuration state should be monitored.
  • poll_interval: Time interval (in milliseconds) to check for file changes.
  • handler: An instance implementing WatcherHandler for handling snapshots and errors.
§Returns
  • Ok(Self): A properly initialized Watcher instance.
  • Err(Error): If any file metadata cannot be retrieved.
Source

pub async fn watch(&mut self)

Starts monitoring the files and system state for changes.

This function continuously checks the monitored files for modifications and observes system state transitions. When a file modification or a relevant state transition (from Draft to Applied) is detected, it triggers the on_snapshot method of the handler.

§Returns
  • Ok(()) if the monitoring process runs smoothly.
  • Err(Error) if an unrecoverable error occurs.
Source

pub async fn check_files_for_changes(&mut self) -> bool

Checks the monitored files for modifications.

Source

pub async fn handle_snapshot(&mut self)

Captures and processes a snapshot of the monitored files and system state.

Source

pub async fn snapshot(&self) -> Result<Snapshot, Error>

Generates a snapshot of the current state of the monitored files.

§Returns
  • Ok(Snapshot): A snapshot containing the contents and metadata of monitored files.
  • Err(Error): If a file cannot be read.
Source

pub async fn force_capture_and_dispatch(&self) -> Result<(), Error>

Forces the capture of a snapshot and dispatches it to the handler.

§Returns
  • Ok(()) if the snapshot was successfully processed by the handler.
  • Err(Error): If an error occurs during snapshot creation or handling.

Auto Trait Implementations§

§

impl<H> Freeze for Watcher<H>
where H: Freeze,

§

impl<H> RefUnwindSafe for Watcher<H>
where H: RefUnwindSafe,

§

impl<H> Send for Watcher<H>
where H: Send,

§

impl<H> Sync for Watcher<H>
where H: Sync,

§

impl<H> Unpin for Watcher<H>
where H: Unpin,

§

impl<H> UnwindSafe for Watcher<H>
where H: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.