### watch Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/struct.Debouncer.html?search=std%3A%3Avec Starts watching a path for file system events. ```APIDOC ## pub fn watch(&mut self, path: impl AsRef, recursive_mode: RecursiveMode) -> Result<()> ### Description Watch the specified path for file system events with the given recursive mode. ``` -------------------------------- ### RecommendedCache::new Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.RecommendedCache.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Constructs a new instance of the cache. ```APIDOC ## pub fn new() -> Self ### Description Construct an empty cache instance. ### Returns - **Self** - A new instance of the cache. ``` -------------------------------- ### Initialize and use a debouncer Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/index.html?search=std%3A%3Avec Create a debouncer with a callback and watch a directory for changes. ```rust use notify_debouncer_full::{notify::*, new_debouncer, DebounceEventResult}; // Select recommended watcher for debouncer. // Using a callback here, could also be a channel. let mut debouncer = new_debouncer(Duration::from_secs(2), None, |result: DebounceEventResult| { match result { Ok(events) => events.iter().for_each(|event| println!("{event:?}")), Err(errors) => errors.iter().for_each(|error| println!("{error:?}")), } }).unwrap(); // Add a path to be watched. All files and directories at that path and // below will be monitored for changes. debouncer.watch(".", RecursiveMode::Recursive).unwrap(); ``` -------------------------------- ### Add Dependency Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/index.html Add the crate to your Cargo.toml dependencies. ```toml [dependencies] notify-debouncer-full = "0.7.0" ``` -------------------------------- ### configure Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/struct.Debouncer.html?search=std%3A%3Avec Configures the debouncer with the provided settings. ```APIDOC ## pub fn configure(&mut self, option: Config) -> Result ### Description Configure the debouncer with the provided `Config` option. ``` -------------------------------- ### Debouncer Configuration and Watching Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/struct.Debouncer.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Methods for configuring the debouncer and managing watched paths. ```APIDOC ## watch(&mut self, path: impl AsRef, recursive_mode: RecursiveMode) -> Result<()> ### Description Starts watching the specified path for file system events. ## unwatch(&mut self, path: impl AsRef) -> Result<()> ### Description Stops watching the specified path. ## configure(&mut self, option: Config) -> Result ### Description Updates the configuration of the debouncer instance. ``` -------------------------------- ### Check Result status with is_ok_and Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Verify if a Result is Ok and matches a predicate. ```rust let x: Result = Ok(2); assert_eq!(x.is_ok_and(|x| x > 1), true); let x: Result = Ok(0); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Err("hey"); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Ok("ownership".to_string()); assert_eq!(x.as_ref().is_ok_and(|x| x.len() > 1), true); println!("still alive {:?}", x); ``` -------------------------------- ### Debouncer Watcher Configuration Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/struct.Debouncer.html?search= Methods for managing file system watches and configuration. ```rust pub fn watch( &mut self, path: impl AsRef, recursive_mode: RecursiveMode, ) -> Result<()> ``` ```rust pub fn unwatch(&mut self, path: impl AsRef) -> Result<()> ``` ```rust pub fn configure(&mut self, option: Config) -> Result ``` ```rust pub fn kind() -> WatcherKind ``` -------------------------------- ### Add dependency to Cargo.toml Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/index.html?search=std%3A%3Avec Basic configuration for adding the crate to a Rust project. ```toml [dependencies] notify-debouncer-full = "0.7.0" ``` ```toml notify-debouncer-full = "0.7.0" notify = { version = "..", features = [".."] } ``` -------------------------------- ### configure Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/struct.Debouncer.html?search=u32+-%3E+bool Updates the configuration of the debouncer. ```APIDOC ## pub fn configure(&mut self, option: Config) -> Result ### Description Applies a new configuration to the debouncer. ``` -------------------------------- ### Convert Result to reference with as_ref Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Create a new Result containing references to the original values. ```rust let x: Result = Ok(2); assert_eq!(x.as_ref(), Ok(&2)); let x: Result = Err("Error"); assert_eq!(x.as_ref(), Err(&"Error")); ``` -------------------------------- ### kind Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/struct.Debouncer.html?search=std%3A%3Avec Returns the kind of watcher being used. ```APIDOC ## pub fn kind() -> WatcherKind ### Description Returns the `WatcherKind` associated with the debouncer. ``` -------------------------------- ### NoCache::new Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/struct.NoCache.html?search= Constructs a new instance of the NoCache struct. ```APIDOC ## pub fn new() -> Self ### Description Constructs an empty cache instance of `NoCache`. ``` -------------------------------- ### FileIdMap::new Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/struct.FileIdMap.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Constructs a new, empty FileIdMap cache. ```APIDOC ## pub fn new() -> Self ### Description Constructs an empty cache for file system IDs. ### Returns - **Self** - An empty instance of FileIdMap. ``` -------------------------------- ### FileIdCache Methods Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.RecommendedCache.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Methods available for interacting with the cache to manage file paths and IDs. ```APIDOC ## cached_file_id(&self, _path: &Path) -> Option> ### Description Get a FileId from the cache for a given path. ## add_path(&mut self, _path: &Path, _recursive_mode: RecursiveMode) ### Description Add a new path to the cache or update its value. ## remove_path(&mut self, _path: &Path) ### Description Remove a path from the cache. ## rescan(&mut self, root_paths: &[(PathBuf, RecursiveMode)]) ### Description Re-scan all provided root paths. ``` -------------------------------- ### Fallback with or Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Returns the provided result if the current result is Err, otherwise returns the Ok value. Arguments are eagerly evaluated. ```rust let x: Result = Ok(2); let y: Result = Err("late error"); assert_eq!(x.or(y), Ok(2)); let x: Result = Err("early error"); let y: Result = Ok(2); assert_eq!(x.or(y), Ok(2)); let x: Result = Err("not a 2"); let y: Result = Err("late error"); assert_eq!(x.or(y), Err("late error")); let x: Result = Ok(2); let y: Result = Ok(100); assert_eq!(x.or(y), Ok(2)); ``` -------------------------------- ### watch Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/struct.Debouncer.html?search= Adds a path to be watched by the debouncer. ```APIDOC ## pub fn watch(&mut self, path: impl AsRef, recursive_mode: RecursiveMode) -> Result<()> ### Description Starts watching the specified path with the given recursive mode. ``` -------------------------------- ### Convert Result to Option with ok Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Convert a Result to an Option, discarding the error. ```rust let x: Result = Ok(2); assert_eq!(x.ok(), Some(2)); let x: Result = Err("Nothing here"); assert_eq!(x.ok(), None); ``` -------------------------------- ### new_debouncer Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/fn.new_debouncer.html Creates a new debounced watcher with the recommended debouncer and the built-in file ID cache. ```APIDOC ## Function: new_debouncer ### Description Creates a new debounced watcher with the recommended debouncer and the built-in file ID cache. Timeout is the amount of time after which a debounced event is emitted. If `tick_rate` is `None`, notify will select a tick rate that is 1/4 of the provided timeout. ### Signature `pub fn new_debouncer(timeout: Duration, tick_rate: Option, event_handler: F) -> Result, Error>` ### Parameters - **timeout** (Duration) - The amount of time after which a debounced event is emitted. - **tick_rate** (Option) - The tick rate for the watcher. If None, 1/4 of the timeout is used. - **event_handler** (F) - The handler for debounced events, must implement DebounceEventHandler. ### Returns - **Result, Error>** - A Result containing the initialized Debouncer or an Error. ``` -------------------------------- ### Into Ok value Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Returns the contained Ok value without panicking, useful for infallible results. ```rust fn only_good_news() -> Result { Ok("this is fine".into()) } ``` -------------------------------- ### Collect Result Iterator Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Demonstrates how collecting an iterator of Results short-circuits on the first Err encountered. ```rust let v = vec![1, 2]; let res: Result, &'static str> = v.iter().map(|x: &u32| x.checked_add(1).ok_or("Overflow!") ).collect(); assert_eq!(res, Ok(vec![2, 3])); ``` ```rust let v = vec![1, 2, 0]; let res: Result, &'static str> = v.iter().map(|x: &u32| x.checked_sub(1).ok_or("Underflow!") ).collect(); assert_eq!(res, Err("Underflow!")); ``` ```rust let v = vec![3, 2, 1, 10]; let mut shared = 0; let res: Result, &'static str> = v.iter().map(|x: &u32| { shared += x; x.checked_sub(2).ok_or("Underflow!") }).collect(); assert_eq!(res, Err("Underflow!")); assert_eq!(shared, 6); ``` -------------------------------- ### RecommendedCache Definition Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.RecommendedCache.html The type alias definition for the recommended cache implementation. ```rust pub type RecommendedCache = NoCache; ``` -------------------------------- ### Unwrap with default value Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Returns the contained Ok value or a provided default. Arguments are eagerly evaluated. ```rust let default = 2; let x: Result = Ok(9); assert_eq!(x.unwrap_or(default), 9); let x: Result = Err("error"); assert_eq!(x.unwrap_or(default), default); ``` -------------------------------- ### Calculate Product of Result Iterator Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Demonstrates using the product method on an iterator of Results, which returns an Err if any parsing operation fails. ```rust let nums = vec!["5", "10", "1", "2"]; let total: Result = nums.iter().map(|w| w.parse::()).product(); assert_eq!(total, Ok(100)); let nums = vec!["5", "10", "one", "2"]; let total: Result = nums.iter().map(|w| w.parse::()).product(); assert!(total.is_err()); ``` -------------------------------- ### Unwrap or default value Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Returns the contained Ok value or the default value for the type if the result is Err. ```rust let good_year_from_input = "1909"; let bad_year_from_input = "190blarg"; let good_year = good_year_from_input.parse().unwrap_or_default(); let bad_year = bad_year_from_input.parse().unwrap_or_default(); assert_eq!(1909, good_year); assert_eq!(0, bad_year); ``` -------------------------------- ### Unwrapping with closure Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html?search= Demonstrates using unwrap_or_else to compute a default value from a closure. ```rust fn count(x: &str) -> usize { x.len() } ``` -------------------------------- ### new_debouncer Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/fn.new_debouncer.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new debounced watcher with the recommended debouncer and the built-in file ID cache. ```APIDOC ## pub fn new_debouncer(timeout: Duration, tick_rate: Option, event_handler: F) -> Result, Error> ### Description Creates a new debounced watcher with the recommended debouncer and the built-in file ID cache. The timeout defines the duration after which a debounced event is emitted. If tick_rate is None, the system selects a tick rate that is 1/4 of the provided timeout. ### Parameters - **timeout** (Duration) - Required - The amount of time after which a debounced event is emitted. - **tick_rate** (Option) - Required - The tick rate for the watcher; if None, it defaults to 1/4 of the timeout. - **event_handler** (F: DebounceEventHandler) - Required - The handler to process debounced events. ### Returns - **Result, Error>** - Returns a Result containing the initialized Debouncer or an Error if initialization fails. ``` -------------------------------- ### Check Result status with is_err_and Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Verify if a Result is Err and matches a predicate. ```rust use std::io::{Error, ErrorKind}; let x: Result = Err(Error::new(ErrorKind::NotFound, "!")); assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), true); let x: Result = Err(Error::new(ErrorKind::PermissionDenied, "!")); assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), false); let x: Result = Ok(123); assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), false); let x: Result = Err("ownership".to_string()); assert_eq!(x.as_ref().is_err_and(|x| x.len() > 1), true); println!("still alive {:?}", x); ``` -------------------------------- ### new_debouncer_opt Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/fn.new_debouncer_opt.html Creates a new debounced watcher with custom configuration. ```APIDOC ## Function: new_debouncer_opt ### Description Creates a new debounced watcher with custom configuration. Timeout is the amount of time after which a debounced event is emitted. If `tick_rate` is `None`, notify will select a tick rate that is 1/4 of the provided timeout. ### Signature `pub fn new_debouncer_opt(timeout: Duration, tick_rate: Option, event_handler: F, file_id_cache: C, config: Config) -> Result, Error>` ### Parameters - **timeout** (Duration) - The amount of time after which a debounced event is emitted. - **tick_rate** (Option) - The tick rate for the watcher. If None, 1/4 of the timeout is used. - **event_handler** (F) - The handler for debounce events. - **file_id_cache** (C) - The cache for file IDs. - **config** (Config) - The configuration settings for the debouncer. ### Returns - **Result, Error>** - Returns a new Debouncer instance or an Error if creation fails. ``` -------------------------------- ### Debouncer Lifecycle Methods Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/struct.Debouncer.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Methods for controlling the lifecycle of the debouncer instance. ```APIDOC ## stop(self) ### Description Stops the debouncer and waits for the event thread to finish. This operation may block for the duration of one tick_rate. ## stop_nonblocking(self) ### Description Stops the debouncer immediately without waiting for the event thread to finish. ``` -------------------------------- ### watch Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/struct.Debouncer.html?search=u32+-%3E+bool Adds a path to be watched by the debouncer with a specified recursive mode. ```APIDOC ## pub fn watch(&mut self, path: impl AsRef, recursive_mode: RecursiveMode) -> Result<()> ### Description Starts watching the specified path for file system events. ``` -------------------------------- ### unwatch Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/struct.Debouncer.html?search=std%3A%3Avec Stops watching a path for file system events. ```APIDOC ## pub fn unwatch(&mut self, path: impl AsRef) -> Result<()> ### Description Stop watching the specified path. ``` -------------------------------- ### Reference Result Values Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html?search= Convert Result to a Result containing references. ```rust let x: Result = Ok(2); assert_eq!(x.as_ref(), Ok(&2)); let x: Result = Err("Error"); assert_eq!(x.as_ref(), Err(&"Error")); ``` ```rust fn mutate(r: &mut Result) { match r.as_mut() { Ok(v) => *v = 42, Err(e) => *e = 0, } } let mut x: Result = Ok(2); mutate(&mut x); assert_eq!(x.unwrap(), 42); let mut x: Result = Err(13); mutate(&mut x); assert_eq!(x.unwrap_err(), 0); ``` -------------------------------- ### Debouncer::watch Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/index.html Adds a path to be watched. All files and directories at that path and below will be monitored for changes. ```APIDOC ## Debouncer::watch(path, recursive_mode) ### Description Adds a path to be watched. All files and directories at that path and below will be monitored for changes. ### Parameters - **path** (AsRef) - Required - The path to watch. - **recursive_mode** (RecursiveMode) - Required - Whether to watch recursively. ### Example ```rust debouncer.watch(".", RecursiveMode::Recursive).unwrap(); ``` ``` -------------------------------- ### Extract Ok values with into_ok Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html?search= Extract the Ok value without panicking. Requires the error type to be infallible. ```rust fn only_good_news() -> Result { Ok("this is fine".into()) } ``` -------------------------------- ### Map Result values with map Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Apply a function to the contained Ok value. ```rust let line = "1\n2\n3\n4\n"; for num in line.lines() { match num.parse::().map(|i| i * 2) { Ok(n) => println!("{n}"), Err(..) => {} } } ``` -------------------------------- ### Debouncer Lifecycle Methods Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/struct.Debouncer.html?search= Methods to control the execution state of the debouncer. ```rust pub fn stop(self) ``` ```rust pub fn stop_nonblocking(self) ``` -------------------------------- ### new_debouncer_opt Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/fn.new_debouncer_opt.html?search=std%3A%3Avec Creates a new debounced watcher with custom configuration. Timeout is the amount of time after which a debounced event is emitted. If tick_rate is None, notify will select a tick rate that is 1/4 of the provided timeout. ```APIDOC ## Function: new_debouncer_opt ### Signature `pub fn new_debouncer_opt(timeout: Duration, tick_rate: Option, event_handler: F, file_id_cache: C, config: Config) -> Result, Error>` ### Description Creates a new debounced watcher with custom configuration. Timeout is the amount of time after which a debounced event is emitted. If `tick_rate` is `None`, notify will select a tick rate that is 1/4 of the provided timeout. ### Parameters - **timeout** (Duration) - The amount of time after which a debounced event is emitted. - **tick_rate** (Option) - The tick rate for the watcher. If None, it defaults to 1/4 of the timeout. - **event_handler** (F) - The handler for debounced events. - **file_id_cache** (C) - The cache for file IDs. - **config** (Config) - The configuration for the debouncer. ### Returns - **Result, Error>** - Returns a new Debouncer instance or an Error if creation fails. ``` -------------------------------- ### Chaining Results with and Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Returns the provided result if the current result is Ok, otherwise returns the Err value. Arguments are eagerly evaluated. ```rust let x: Result = Ok(2); let y: Result<&str, &str> = Err("late error"); assert_eq!(x.and(y), Err("late error")); let x: Result = Err("early error"); let y: Result<&str, &str> = Ok("foo"); assert_eq!(x.and(y), Err("early error")); let x: Result = Err("not a 2"); let y: Result<&str, &str> = Err("late error"); assert_eq!(x.and(y), Err("not a 2")); let x: Result = Ok(2); let y: Result<&str, &str> = Ok("different result type"); assert_eq!(x.and(y), Ok("different result type")); ``` -------------------------------- ### Calculate Sum of Result Iterator Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Demonstrates using the sum method on an iterator of Results, which short-circuits and returns an Err if a negative element is encountered. ```rust let f = |&x: &i32| if x < 0 { Err("Negative element found") } else { Ok(x) }; let v = vec![1, 2]; let res: Result = v.iter().map(f).sum(); assert_eq!(res, Ok(3)); let v = vec![1, -2]; let res: Result = v.iter().map(f).sum(); assert_eq!(res, Err("Negative element found")); ``` -------------------------------- ### Add Dependency with Custom Notify Features Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/index.html Specify notify explicitly if custom features are required. ```toml notify-debouncer-full = "0.7.0" notify = { version = "..", features = [".."] } ``` -------------------------------- ### new_debouncer function signature Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/fn.new_debouncer.html?search=u32+-%3E+bool Defines the parameters and return type for initializing a new debouncer instance. ```rust pub fn new_debouncer( timeout: Duration, tick_rate: Option, event_handler: F, ) -> Result, Error> ``` -------------------------------- ### Map Result to Value with map_or_default Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Maps Ok to a value using a function, or returns the default value for the type if Err. ```rust let x: Result<_, &str> = Ok("foo"); let y: Result<&str, _> = Err("bar"); assert_eq!(x.map_or_default(|x| x.len()), 3); assert_eq!(y.map_or_default(|y| y.len()), 0); ``` -------------------------------- ### Check Result status with is_ok Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Verify if a Result contains an Ok value. ```rust let x: Result = Ok(-3); assert_eq!(x.is_ok(), true); let x: Result = Err("Some error message"); assert_eq!(x.is_ok(), false); ``` -------------------------------- ### Function Signature for new_debouncer_opt Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/fn.new_debouncer_opt.html The signature defines the required traits for the event handler, watcher, and file ID cache, along with configuration parameters. ```rust pub fn new_debouncer_opt( timeout: Duration, tick_rate: Option, event_handler: F, file_id_cache: C, config: Config, ) -> Result, Error> ``` -------------------------------- ### Convert Result to mutable reference with as_mut Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Create a new Result containing mutable references to the original values. ```rust fn mutate(r: &mut Result) { match r.as_mut() { Ok(v) => *v = 42, Err(e) => *e = 0, } } let mut x: Result = Ok(2); mutate(&mut x); assert_eq!(x.unwrap(), 42); let mut x: Result = Err(13); mutate(&mut x); assert_eq!(x.unwrap_err(), 0); ``` -------------------------------- ### Define FileIdMap struct Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/struct.FileIdMap.html The definition of the FileIdMap struct as it appears in the crate source. ```rust pub struct FileIdMap { /* private fields */ } ``` -------------------------------- ### Inspect Ok Result Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Calls a function with a reference to the contained value if Ok, returning the original result. ```rust let x: u8 = "4" .parse::() .inspect(|x| println!("original: {x}")) .map(|x| x.pow(3)) .expect("failed to parse number"); ``` -------------------------------- ### Check Result Status Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html?search= Methods to verify if a Result is Ok or Err. ```rust let x: Result = Ok(-3); assert_eq!(x.is_ok(), true); let x: Result = Err("Some error message"); assert_eq!(x.is_ok(), false); ``` ```rust let x: Result = Ok(-3); assert_eq!(x.is_err(), false); let x: Result = Err("Some error message"); assert_eq!(x.is_err(), true); ``` -------------------------------- ### Deref Result with as_deref Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Coerces the Ok variant via Deref and returns a new Result. ```rust let x: Result = Ok("hello".to_string()); let y: Result<&str, &u32> = Ok("hello"); assert_eq!(x.as_deref(), y); let x: Result = Err(42); let y: Result<&str, &u32> = Err(&42); assert_eq!(x.as_deref(), y); ``` -------------------------------- ### Convert Result to Option with err Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Convert a Result to an Option, discarding the success value. ```rust let x: Result = Ok(2); assert_eq!(x.err(), None); let x: Result = Err("Nothing here"); assert_eq!(x.err(), Some("Nothing here")); ``` -------------------------------- ### Check Result with Predicate Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html?search= Verify Result status using a predicate function. ```rust let x: Result = Ok(2); assert_eq!(x.is_ok_and(|x| x > 1), true); let x: Result = Ok(0); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Err("hey"); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Ok("ownership".to_string()); assert_eq!(x.as_ref().is_ok_and(|x| x.len() > 1), true); println!("still alive {:?}", x); ``` ```rust use std::io::{Error, ErrorKind}; let x: Result = Err(Error::new(ErrorKind::NotFound, "!")); assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), true); let x: Result = Err(Error::new(ErrorKind::PermissionDenied, "!")); assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), false); let x: Result = Ok(123); assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), false); let x: Result = Err("ownership".to_string()); assert_eq!(x.as_ref().is_err_and(|x| x.len() > 1), true); println!("still alive {:?}", x); ``` -------------------------------- ### Expect a Result value Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Expect returns the contained Ok value or panics with a custom message if the result is Err. ```rust let x: Result = Err("emergency failure"); x.expect("Testing expect"); // panics with `Testing expect: emergency failure` ``` ```rust let path = std::env::var("IMPORTANT_PATH") .expect("env variable `IMPORTANT_PATH` should be set by `wrapper_script.sh`"); ``` -------------------------------- ### FileIdCache Trait Methods Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/struct.FileIdMap.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Methods available for interacting with the FileIdMap cache, including path management and rescanning. ```APIDOC ## cached_file_id(&self, path: &Path) -> Option> ### Description Retrieves a FileId from the cache for a specified path. ## add_path(&mut self, path: &Path, recursive_mode: RecursiveMode) ### Description Adds a new path to the cache or updates the existing value for the path. ## remove_path(&mut self, path: &Path) ### Description Removes a path from the cache. ## rescan(&mut self, root_paths: &[(PathBuf, RecursiveMode)]) ### Description Performs a re-scan of all provided root paths. ``` -------------------------------- ### new_debouncer Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/fn.new_debouncer.html?search=u32+-%3E+bool Creates a new debounced watcher with a specified timeout, optional tick rate, and event handler. ```APIDOC ## Function: new_debouncer ### Description Creates a new debounced watcher with the recommended debouncer and the built-in file ID cache. The timeout defines the duration after which a debounced event is emitted. If the tick_rate is not provided, it defaults to 1/4 of the timeout. ### Signature `pub fn new_debouncer(timeout: Duration, tick_rate: Option, event_handler: F) -> Result, Error>` ### Parameters - **timeout** (Duration) - The amount of time after which a debounced event is emitted. - **tick_rate** (Option) - Optional tick rate for the watcher. If None, defaults to 1/4 of the timeout. - **event_handler** (F) - The handler implementation for debounced events. ### Returns - **Result, Error>** - Returns a new Debouncer instance or an Error if initialization fails. ``` -------------------------------- ### Deprecated Debouncer Methods Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/struct.Debouncer.html?search= Methods that are no longer recommended for use. ```rust pub fn watcher(&mut self) ``` ```rust pub fn cache(&mut self) ``` -------------------------------- ### Unwrap a Result value Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Unwrap returns the contained Ok value or panics if the result is Err. ```rust let x: Result = Ok(2); assert_eq!(x.unwrap(), 2); ``` ```rust let x: Result = Err("emergency failure"); x.unwrap(); // panics with `emergency failure` ``` -------------------------------- ### Define NoCache struct Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/struct.NoCache.html The definition of the NoCache struct. ```rust pub struct NoCache; ``` -------------------------------- ### unwatch Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/struct.Debouncer.html?search=u32+-%3E+bool Removes a path from the list of watched paths. ```APIDOC ## pub fn unwatch(&mut self, path: impl AsRef) -> Result<()> ### Description Stops watching the specified path. ``` -------------------------------- ### Iterate Result Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Returns an iterator that yields the contained value if Ok, or nothing if Err. ```rust let x: Result = Ok(7); assert_eq!(x.iter().next(), Some(&7)); let x: Result = Err("nothing!"); assert_eq!(x.iter().next(), None); ``` -------------------------------- ### Map Result to Value with map_or Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Returns a default value if Err, or applies a function to the Ok value. Note that arguments are eagerly evaluated. ```rust let x: Result<_, &str> = Ok("foo"); assert_eq!(x.map_or(42, |v| v.len()), 3); let x: Result<&str, _> = Err("bar"); assert_eq!(x.map_or(42, |v| v.len()), 42); ``` -------------------------------- ### Map Result to Value with map_or_else Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Maps a Result to a value by applying a fallback function to Err or a transformation function to Ok. This is lazily evaluated. ```rust let k = 21; let x : Result<_, &str> = Ok("foo"); assert_eq!(x.map_or_else(|e| k * 2, |v| v.len()), 3); let x : Result<&str, _> = Err("bar"); assert_eq!(x.map_or_else(|e| k * 2, |v| v.len()), 42); ``` -------------------------------- ### Unwrap an error Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Unwrap_err returns the contained Err value or panics if the result is Ok. ```rust let x: Result = Ok(2); x.unwrap_err(); // panics with `2` ``` ```rust let x: Result = Err("emergency failure"); assert_eq!(x.unwrap_err(), "emergency failure"); ``` -------------------------------- ### Fallback with or_else Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Calls a closure if the result is Err, otherwise returns the Ok value. ```rust fn sq(x: u32) -> Result { Ok(x * x) } fn err(x: u32) -> Result { Err(x) } assert_eq!(Ok(2).or_else(sq).or_else(sq), Ok(2)); assert_eq!(Ok(2).or_else(err).or_else(sq), Ok(2)); assert_eq!(Err(3).or_else(sq).or_else(err), Ok(9)); assert_eq!(Err(3).or_else(err).or_else(err), Err(3)); ``` -------------------------------- ### Expect an error Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Expect_err returns the contained Err value or panics if the result is Ok. ```rust let x: Result = Ok(10); x.expect_err("Testing expect_err"); // panics with `Testing expect_err: 10` ``` -------------------------------- ### Chaining Results with and_then Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Calls a closure if the result is Ok, otherwise returns the Err value. Useful for chaining fallible operations. ```rust fn sq_then_to_string(x: u32) -> Result { x.checked_mul(x).map(|sq| sq.to_string()).ok_or("overflowed") } assert_eq!(Ok(2).and_then(sq_then_to_string), Ok(4.to_string())); assert_eq!(Ok(1_000_000).and_then(sq_then_to_string), Err("overflowed")); assert_eq!(Err("not a number").and_then(sq_then_to_string), Err("not a number")); ``` ```rust use std::{io::ErrorKind, path::Path}; // Note: on Windows "/" maps to "C:\" let root_modified_time = Path::new("/").metadata().and_then(|md| md.modified()); assert!(root_modified_time.is_ok()); let should_fail = Path::new("/bad/path").metadata().and_then(|md| md.modified()); assert!(should_fail.is_err()); assert_eq!(should_fail.unwrap_err().kind(), ErrorKind::NotFound); ``` -------------------------------- ### FileIdCache Trait Definition Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/trait.FileIdCache.html The core trait definition for FileIdCache, outlining required methods for path management and the provided rescan method. ```rust pub trait FileIdCache { // Required methods fn cached_file_id(&self, path: &Path) -> Option>; fn add_path(&mut self, path: &Path, recursive_mode: RecursiveMode); fn remove_path(&mut self, path: &Path); // Provided method fn rescan(&mut self, root_paths: &[(PathBuf, RecursiveMode)]) { ... } } ``` -------------------------------- ### pub unsafe fn unwrap_unchecked(self) -> T Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html?search=u32+-%3E+bool Returns the contained Ok value, consuming the self value, without checking that the value is not an Err. Calling this method on an Err is undefined behavior. ```APIDOC ## pub unsafe fn unwrap_unchecked(self) -> T ### Description Returns the contained `Ok` value, consuming the `self` value, without checking that the value is not an `Err`. ### Safety Calling this method on an `Err` is _undefined behavior_. ``` -------------------------------- ### Extracting Err with into_err Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Returns the contained Err value without panicking. This is a nightly-only experimental API. ```rust fn only_bad_news() -> Result { Err("Oops, it failed".into()) } let error: String = only_bad_news().into_err(); println!("{error}"); ``` -------------------------------- ### Mutably Deref Result with as_deref_mut Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Coerces the Ok variant via DerefMut and returns a new Result. ```rust let mut s = "HELLO".to_string(); let mut x: Result = Ok("hello".to_string()); let y: Result<&mut str, &mut u32> = Ok(&mut s); assert_eq!(x.as_deref_mut().map(|x| { x.make_ascii_uppercase(); x }), y); let mut i = 42; let mut x: Result = Err(42); let y: Result<&mut str, &mut u32> = Err(&mut i); assert_eq!(x.as_deref_mut().map(|x| { x.make_ascii_uppercase(); x }), y); ``` -------------------------------- ### Inspect Err Result Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Calls a function with a reference to the contained value if Err, returning the original result. ```rust use std::{fs, io}; fn read() -> io::Result { fs::read_to_string("address.txt") .inspect_err(|e| eprintln!("failed to read file: {e}")) } ``` -------------------------------- ### Check Result status with is_err Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Verify if a Result contains an Err value. ```rust let x: Result = Ok(-3); assert_eq!(x.is_err(), false); let x: Result = Err("Some error message"); assert_eq!(x.is_err(), true); ``` -------------------------------- ### Unwrap Unchecked Methods Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html?search= Unsafe methods to extract values from Result without checking for Err or Ok variants. Calling these on the wrong variant results in undefined behavior. ```rust let x: Result = Ok(2); assert_eq!(unsafe { x.unwrap_unchecked() }, 2); ``` ```rust let x: Result = Err("emergency failure"); unsafe { x.unwrap_unchecked() }; // Undefined behavior! ``` ```rust let x: Result = Ok(2); unsafe { x.unwrap_err_unchecked() }; // Undefined behavior! ``` ```rust let x: Result = Err("emergency failure"); assert_eq!(unsafe { x.unwrap_err_unchecked() }, "emergency failure"); ``` -------------------------------- ### pub unsafe fn unwrap_err_unchecked(self) -> E Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html?search=u32+-%3E+bool Returns the contained Err value, consuming the self value, without checking that the value is not an Ok. Calling this method on an Ok is undefined behavior. ```APIDOC ## pub unsafe fn unwrap_err_unchecked(self) -> E ### Description Returns the contained `Err` value, consuming the `self` value, without checking that the value is not an `Ok`. ### Safety Calling this method on an `Ok` is _undefined behavior_. ``` -------------------------------- ### Implement DebounceEventHandler Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/trait.DebounceEventHandler.html A custom implementation of the trait that prints received events or errors to the console. ```rust /// Prints received events struct EventPrinter; impl DebounceEventHandler for EventPrinter { fn handle_event(&mut self, result: DebounceEventResult) { match result { Ok(events) => events.iter().for_each(|event| println!("{event:?}")), Err(errors) => errors.iter().for_each(|error| println!("{error:?}")), } } } ``` -------------------------------- ### stop_nonblocking Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/struct.Debouncer.html?search=u32+-%3E+bool Stops the debouncer immediately without waiting for the event thread to finish. ```APIDOC ## pub fn stop_nonblocking(self) ### Description Stop the debouncer, does not wait for the event thread to finish. ``` -------------------------------- ### IntoIterator for Result Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Converts a Result into an iterator that yields the contained value if Ok, or nothing if Err. ```rust let x: Result = Ok(5); let v: Vec = x.into_iter().collect(); assert_eq!(v, [5]); let x: Result = Err("nothing!"); let v: Vec = x.into_iter().collect(); assert_eq!(v, []); ``` -------------------------------- ### DebouncedEvent Struct Definition Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/struct.DebouncedEvent.html The primary structure containing the original event and the time it occurred. ```rust pub struct DebouncedEvent { pub event: Event, pub time: Instant, } ``` -------------------------------- ### Iterate mutably over Result Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Use iter_mut to obtain a mutable iterator over the contained value if the result is Ok. ```rust let mut x: Result = Ok(7); match x.iter_mut().next() { Some(v) => *v = 40, None => {}, } assert_eq!(x, Ok(40)); let mut x: Result = Err("nothing!"); assert_eq!(x.iter_mut().next(), None); ``` -------------------------------- ### Map Result Error with map_err Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Transforms the Err variant while leaving the Ok variant untouched. ```rust fn stringify(x: u32) -> String { format!("error code: {x}") } let x: Result = Ok(2); assert_eq!(x.map_err(stringify), Ok(2)); let x: Result = Err(13); assert_eq!(x.map_err(stringify), Err("error code: 13".to_string())); ``` -------------------------------- ### Debouncer Struct Definition Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/struct.Debouncer.html?search=std%3A%3Avec The primary structure for the debouncer, which requires a watcher and a file ID cache. ```rust pub struct Debouncer { /* private fields */ } ``` -------------------------------- ### Unwrap Result Unchecked Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Unwraps a Result without checking for Err, which is undefined behavior if the result is an Err. ```rust let x: Result = Ok(2); assert_eq!(unsafe { x.unwrap_unchecked() }, 2); ``` ```rust let x: Result = Err("emergency failure"); unsafe { x.unwrap_unchecked() }; // Undefined behavior! ``` -------------------------------- ### Unwrap Err Unchecked Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html Unwraps the Err variant without checking for Ok, which is undefined behavior if the result is an Ok. ```rust let x: Result = Ok(2); unsafe { x.unwrap_err_unchecked() }; // Undefined behavior! ``` ```rust let x: Result = Err("emergency failure"); assert_eq!(unsafe { x.unwrap_err_unchecked() }, "emergency failure"); ``` -------------------------------- ### Define DebounceEventHandler trait Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/trait.DebounceEventHandler.html The trait definition requiring Send and 'static bounds for event handling. ```rust pub trait DebounceEventHandler: Send + 'static { // Required method fn handle_event(&mut self, event: DebounceEventResult); } ``` -------------------------------- ### stop Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/struct.Debouncer.html?search=u32+-%3E+bool Stops the debouncer and waits for the event thread to finish. This operation may block for the duration of one tick_rate. ```APIDOC ## pub fn stop(self) ### Description Stop the debouncer, waits for the event thread to finish. May block for the duration of one `tick_rate`. ``` -------------------------------- ### Represent DebounceEventResult as an Enum Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html The conceptual enum structure of the DebounceEventResult type. ```rust pub enum DebounceEventResult { Ok(Vec), Err(Vec), } ``` -------------------------------- ### Define DebounceEventResult Source: https://docs.rs/notify-debouncer-full/latest/notify_debouncer_full/type.DebounceEventResult.html The type alias definition for DebounceEventResult. ```rust pub type DebounceEventResult = Result, Vec>; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.