#[non_exhaustive]pub struct Watch {
pub shell_commands: Vec<String>,
pub cargo_commands: Vec<String>,
pub watch_paths: Vec<PathBuf>,
pub exclude_paths: Vec<PathBuf>,
pub workspace_exclude_paths: Vec<PathBuf>,
pub debounce: Duration,
/* private fields */
}Expand description
Watches over your project’s source code, relaunching a given command when changes are detected.
Use Watch::lock to obtain a WatchLock that can be shared with external
code (e.g. an HTTP server) to coordinate reads with ongoing rebuilds.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.shell_commands: Vec<String>Shell command(s) to execute on changes.
cargo_commands: Vec<String>Cargo command(s) to execute on changes.
The default is [ check ]
watch_paths: Vec<PathBuf>Watch specific file(s) or folder(s).
The default is the workspace root.
exclude_paths: Vec<PathBuf>Paths or glob patterns that will be excluded.
Relative values are resolved from the current working directory.
workspace_exclude_paths: Vec<PathBuf>Paths or glob patterns, relative to the workspace root, that will be excluded.
debounce: DurationQuiet period after the last detected change before the command is (re)started. If another change arrives while a build is running the build is cancelled and the timer resets, so only the latest state is ever built.
The default is 1 second.
Implementations§
Source§impl Watch
impl Watch
Sourcepub fn watch_path(self, path: impl AsRef<Path>) -> Self
pub fn watch_path(self, path: impl AsRef<Path>) -> Self
Add a path to watch for changes.
Sourcepub fn watch_paths(
self,
paths: impl IntoIterator<Item = impl AsRef<Path>>,
) -> Self
pub fn watch_paths( self, paths: impl IntoIterator<Item = impl AsRef<Path>>, ) -> Self
Add multiple paths to watch for changes.
Sourcepub fn exclude_path(self, path: impl AsRef<Path>) -> Self
pub fn exclude_path(self, path: impl AsRef<Path>) -> Self
Add a path that will be ignored if changes are detected.
Sourcepub fn exclude_paths(
self,
paths: impl IntoIterator<Item = impl AsRef<Path>>,
) -> Self
pub fn exclude_paths( self, paths: impl IntoIterator<Item = impl AsRef<Path>>, ) -> Self
Add multiple paths that will be ignored if changes are detected.
Sourcepub fn exclude_workspace_path(self, path: impl AsRef<Path>) -> Self
pub fn exclude_workspace_path(self, path: impl AsRef<Path>) -> Self
Add a path, relative to the workspace, that will be ignored if changes are detected.
Sourcepub fn exclude_workspace_paths(
self,
paths: impl IntoIterator<Item = impl AsRef<Path>>,
) -> Self
pub fn exclude_workspace_paths( self, paths: impl IntoIterator<Item = impl AsRef<Path>>, ) -> Self
Add multiple paths, relative to the workspace, that will be ignored if changes are detected.
Sourcepub fn lock(&self) -> WatchLock
pub fn lock(&self) -> WatchLock
Return the shared lock used by this watcher.
Clone and share this lock with external code (e.g. HTTP handlers) to coordinate with watch-driven command execution.
§Lock lifecycle
run acquires the write lock immediately when it is called — before the
first command is even spawned. Any code that calls WatchLock::acquire will therefore
block until the first build completes. This is intentional: it prevents readers from
observing an empty or incomplete dist directory before the initial build has finished.
The write lock is then re-acquired on every subsequent rebuild and released once the
command sequence succeeds.
Sourcepub fn debounce(self, duration: Duration) -> Self
pub fn debounce(self, duration: Duration) -> Self
Set the debounce quiet period.
The command will not start (or restart) until no change has been detected for this duration. The default is 1 second.
Sourcepub fn run(self, commands: impl Into<CommandList>) -> Result<()>
pub fn run(self, commands: impl Into<CommandList>) -> Result<()>
Run the given command, monitor the watched paths and relaunch the
command when changes are detected.
The command starts immediately. If a change is detected while it is
running, the command is cancelled and the debounce timer resets; the
command only restarts once the source tree has been quiet for the
configured debounce duration.
Workspace’s target directory and hidden paths are excluded by default.
Trait Implementations§
Source§impl Args for Watch
impl Args for Watch
Source§fn augment_args<'b>(__clap_app: Command) -> Command
fn augment_args<'b>(__clap_app: Command) -> Command
Source§fn augment_args_for_update<'b>(__clap_app: Command) -> Command
fn augment_args_for_update<'b>(__clap_app: Command) -> Command
Command so it can instantiate self via
FromArgMatches::update_from_arg_matches_mut Read moreSource§impl CommandFactory for Watch
impl CommandFactory for Watch
Source§impl FromArgMatches for Watch
impl FromArgMatches for Watch
Source§fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
Source§fn from_arg_matches_mut(
__clap_arg_matches: &mut ArgMatches,
) -> Result<Self, Error>
fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches, ) -> Result<Self, Error>
Source§fn update_from_arg_matches(
&mut self,
__clap_arg_matches: &ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches( &mut self, __clap_arg_matches: &ArgMatches, ) -> Result<(), Error>
ArgMatches to self.Source§fn update_from_arg_matches_mut(
&mut self,
__clap_arg_matches: &mut ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches_mut( &mut self, __clap_arg_matches: &mut ArgMatches, ) -> Result<(), Error>
ArgMatches to self.