Struct FileWatcherConfig

Source
pub struct FileWatcherConfig<T, E> {
    pub log_name: String,
    pub file: PathBuf,
    pub parser: Arc<dyn Fn(Vec<u8>) -> Result<T, E> + Send + Sync>,
    pub retry_interval: Duration,
}
Expand description

really-notify primary input. [T] is the target parse type, i.e. your serde-deserializable Config struct. [E] is the generic error type that your parser can fail with.

Fields§

§log_name: String

Cosmetic, used for logs to be consistent with application terminology

§file: PathBuf

Path to the file you are interested in changes of. Do your worse with symlinks here.

§parser: Arc<dyn Fn(Vec<u8>) -> Result<T, E> + Send + Sync>

Parser function to transform a modified target file into our desired output. If you just want raw bytes, you can pass it through, or not set this at all.

§retry_interval: Duration

Defaults to one second, how often to attempt reparsing/error recovery.

Implementations§

Source§

impl FileWatcherConfig<Vec<u8>, Infallible>

Source

pub fn new(file: impl AsRef<Path>, log_name: impl AsRef<str>) -> Self

Source§

impl<T: Send + 'static, E: Display + Send + 'static> FileWatcherConfig<T, E>

Source

pub fn with_parser<T2: Send + 'static, E2: Display + Send + 'static>( self, func: impl Fn(Vec<u8>) -> Result<T2, E2> + Send + Sync + 'static, ) -> FileWatcherConfig<T2, E2>

Set a new parser and adjust the FileWatcherConfig type parameters as needed.

Source

pub fn with_retry_interval(self, retry_interval: Duration) -> Self

Set an alternative retry_interval

Source

pub fn start(self) -> Receiver<T>

Run the watcher. Dropping/closing this receiver will cause an immediate cleanup.

Auto Trait Implementations§

§

impl<T, E> Freeze for FileWatcherConfig<T, E>

§

impl<T, E> !RefUnwindSafe for FileWatcherConfig<T, E>

§

impl<T, E> Send for FileWatcherConfig<T, E>

§

impl<T, E> Sync for FileWatcherConfig<T, E>

§

impl<T, E> Unpin for FileWatcherConfig<T, E>

§

impl<T, E> !UnwindSafe for FileWatcherConfig<T, E>

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.