Add InitConfig::builder() to be a little more idiomatic

Neat side effect: keeps rust-analyzer from complaining about unknown types
(because it doesn't expand the builder macro)!
This commit is contained in:
Félix Saparelli 2021-08-24 19:59:11 +12:00
parent b4ead7f5fb
commit 05afb141b6
No known key found for this signature in database
GPG Key ID: B948C4BAE44FC474
4 changed files with 14 additions and 7 deletions

View File

@ -1,6 +1,6 @@
use watchexec::{ use watchexec::{
action::{Action, Outcome}, action::{Action, Outcome},
config::{InitConfigBuilder, RuntimeConfig}, config::{InitConfig, RuntimeConfig},
error::ReconfigError, error::ReconfigError,
fs::Watcher, fs::Watcher,
signal::Signal, signal::Signal,
@ -13,14 +13,14 @@ async fn main() -> color_eyre::eyre::Result<()> {
tracing_subscriber::fmt::init(); tracing_subscriber::fmt::init();
color_eyre::install()?; color_eyre::install()?;
let mut init = InitConfigBuilder::default(); let mut init = InitConfig::builder();
init.on_error(|err| async move { init.on_error(|err| async move {
eprintln!("Watchexec Runtime Error: {}", err); eprintln!("Watchexec Runtime Error: {}", err);
Ok::<(), std::convert::Infallible>(()) Ok::<(), std::convert::Infallible>(())
}); });
let mut runtime = RuntimeConfig::default(); let mut runtime = RuntimeConfig::default();
runtime.pathset(["src"]); runtime.pathset(["src", "dontexist", "examples"]);
runtime.command(["date"]); runtime.command(["date"]);
let wx = Watchexec::new(init.build()?, runtime.clone())?; let wx = Watchexec::new(init.build()?, runtime.clone())?;

View File

@ -139,6 +139,13 @@ pub struct InitConfig {
pub event_channel_size: usize, pub event_channel_size: usize,
} }
impl InitConfig {
/// Returns a new [`InitConfigBuilder`] for builder the initial configuration.
pub fn builder() -> InitConfigBuilder {
InitConfigBuilder::default()
}
}
impl InitConfigBuilder { impl InitConfigBuilder {
/// Set the runtime error handler. /// Set the runtime error handler.
/// ///

View File

@ -17,13 +17,13 @@
//! use watchexec::{ //! use watchexec::{
//! Watchexec, //! Watchexec,
//! action::{Action, Outcome}, //! action::{Action, Outcome},
//! config::{InitConfigBuilder, RuntimeConfig}, //! config::{InitConfig, RuntimeConfig},
//! handler::{Handler as _, PrintDebug}, //! handler::{Handler as _, PrintDebug},
//! }; //! };
//! //!
//! #[tokio::main] //! #[tokio::main]
//! async fn main() -> Result<(), Report> { //! async fn main() -> Result<(), Report> {
//! let mut init = InitConfigBuilder::default(); //! let mut init = InitConfig::builder();
//! init.on_error(PrintDebug(std::io::stderr())); //! init.on_error(PrintDebug(std::io::stderr()));
//! //!
//! let mut runtime = RuntimeConfig::default(); //! let mut runtime = RuntimeConfig::default();

View File

@ -2,7 +2,7 @@ use std::time::Duration;
use tokio::time::sleep; use tokio::time::sleep;
use watchexec::{ use watchexec::{
config::{InitConfigBuilder, RuntimeConfig}, config::{InitConfig, RuntimeConfig},
Watchexec, Watchexec,
}; };
@ -11,7 +11,7 @@ async fn main() -> color_eyre::eyre::Result<()> {
tracing_subscriber::fmt::init(); tracing_subscriber::fmt::init();
color_eyre::install()?; color_eyre::install()?;
let mut init = InitConfigBuilder::default(); let mut init = InitConfig::builder();
init.on_error(|err| async move { init.on_error(|err| async move {
eprintln!("Watchexec Runtime Error: {}", err); eprintln!("Watchexec Runtime Error: {}", err);
Ok::<(), std::convert::Infallible>(()) Ok::<(), std::convert::Infallible>(())