From 05afb141b634c54bc8d4d0a8f8230cf61a9227fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Tue, 24 Aug 2021 19:59:11 +1200 Subject: [PATCH] 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)! --- lib/examples/demo.rs | 6 +++--- lib/src/config.rs | 7 +++++++ lib/src/lib.rs | 4 ++-- lib/tests/error_handler.rs | 4 ++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/examples/demo.rs b/lib/examples/demo.rs index 56566f0..fb8439f 100644 --- a/lib/examples/demo.rs +++ b/lib/examples/demo.rs @@ -1,6 +1,6 @@ use watchexec::{ action::{Action, Outcome}, - config::{InitConfigBuilder, RuntimeConfig}, + config::{InitConfig, RuntimeConfig}, error::ReconfigError, fs::Watcher, signal::Signal, @@ -13,14 +13,14 @@ async fn main() -> color_eyre::eyre::Result<()> { tracing_subscriber::fmt::init(); color_eyre::install()?; - let mut init = InitConfigBuilder::default(); + let mut init = InitConfig::builder(); init.on_error(|err| async move { eprintln!("Watchexec Runtime Error: {}", err); Ok::<(), std::convert::Infallible>(()) }); let mut runtime = RuntimeConfig::default(); - runtime.pathset(["src"]); + runtime.pathset(["src", "dontexist", "examples"]); runtime.command(["date"]); let wx = Watchexec::new(init.build()?, runtime.clone())?; diff --git a/lib/src/config.rs b/lib/src/config.rs index 4a1c128..149fc7b 100644 --- a/lib/src/config.rs +++ b/lib/src/config.rs @@ -139,6 +139,13 @@ pub struct InitConfig { pub event_channel_size: usize, } +impl InitConfig { + /// Returns a new [`InitConfigBuilder`] for builder the initial configuration. + pub fn builder() -> InitConfigBuilder { + InitConfigBuilder::default() + } +} + impl InitConfigBuilder { /// Set the runtime error handler. /// diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 6dadd0a..4f916f2 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -17,13 +17,13 @@ //! use watchexec::{ //! Watchexec, //! action::{Action, Outcome}, -//! config::{InitConfigBuilder, RuntimeConfig}, +//! config::{InitConfig, RuntimeConfig}, //! handler::{Handler as _, PrintDebug}, //! }; //! //! #[tokio::main] //! async fn main() -> Result<(), Report> { -//! let mut init = InitConfigBuilder::default(); +//! let mut init = InitConfig::builder(); //! init.on_error(PrintDebug(std::io::stderr())); //! //! let mut runtime = RuntimeConfig::default(); diff --git a/lib/tests/error_handler.rs b/lib/tests/error_handler.rs index 2160dfa..6bbe57b 100644 --- a/lib/tests/error_handler.rs +++ b/lib/tests/error_handler.rs @@ -2,7 +2,7 @@ use std::time::Duration; use tokio::time::sleep; use watchexec::{ - config::{InitConfigBuilder, RuntimeConfig}, + config::{InitConfig, RuntimeConfig}, Watchexec, }; @@ -11,7 +11,7 @@ async fn main() -> color_eyre::eyre::Result<()> { tracing_subscriber::fmt::init(); color_eyre::install()?; - let mut init = InitConfigBuilder::default(); + let mut init = InitConfig::builder(); init.on_error(|err| async move { eprintln!("Watchexec Runtime Error: {}", err); Ok::<(), std::convert::Infallible>(())