From 6c3c06e39c0deb0925bdd39ace6f54814b14e5d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sun, 22 Aug 2021 20:49:24 +1200 Subject: [PATCH] Stop using Builder for RuntimeConfig --- lib/examples/print_out.rs | 4 ++-- lib/src/config.rs | 14 +++++++------- lib/src/lib.rs | 8 ++++---- lib/tests/error_handler.rs | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/examples/print_out.rs b/lib/examples/print_out.rs index ad8d858..13c6f75 100644 --- a/lib/examples/print_out.rs +++ b/lib/examples/print_out.rs @@ -2,7 +2,7 @@ use std::time::Duration; use tokio::time::sleep; use watchexec::{ - config::{InitConfigBuilder, RuntimeConfigBuilder}, + config::{InitConfigBuilder, RuntimeConfig}, Watchexec, }; @@ -19,7 +19,7 @@ async fn main() -> color_eyre::eyre::Result<()> { })) .build()?; - let runtime = RuntimeConfigBuilder::default().build()?; + let runtime = RuntimeConfig::default(); let wx = Watchexec::new(init, runtime)?; wx.main(); diff --git a/lib/src/config.rs b/lib/src/config.rs index 2978ccc..d319731 100644 --- a/lib/src/config.rs +++ b/lib/src/config.rs @@ -1,30 +1,30 @@ -use std::fmt; +use std::{fmt, sync::Arc, time::Duration}; +use atomic_take::AtomicTake; use derive_builder::Builder; -use crate::{error::RuntimeError, handler::Handler}; +use crate::{action::Action, error::RuntimeError, handler::Handler}; /// Runtime configuration for [`Watchexec`][crate::Watchexec]. /// /// This is used both when constructing the instance (as initial configuration) and to reconfigure /// it at runtime via [`Watchexec::reconfig()`][crate::Watchexec::reconfig()]. /// -/// Use [`RuntimeConfigBuilder`] to build a new one, or modify an existing one. This struct is -/// marked non-exhaustive such that new options may be added without breaking change. -#[derive(Builder, Clone, Debug)] +/// Use [`RuntimeConfig::default()`] to build a new one, or modify an existing one. This struct is +/// marked non-exhaustive such that new options may be added without breaking change. You can make +/// changes through the fields directly, or use the convenience (chainable!) methods instead. +#[derive(Clone, Debug, Default)] #[non_exhaustive] pub struct RuntimeConfig { /// Working data for the filesystem event source. /// /// This notably includes the path set to be watched. - #[builder(default)] pub fs: crate::fs::WorkingData, /// Working data for the action processing. /// /// This is the task responsible for scheduling the actions in response to events, applying the /// filtering, etc. - #[builder(default)] pub action: crate::action::WorkingData, } diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 4073321..71e96ba 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -19,13 +19,13 @@ //! let init = InitConfigBuilder::default() //! .error_handler(PrintDebug(std::io::stderr())); //! -//! let mut runtime = RuntimeConfigBuilder::default() -//! config.pathset(["watchexec.conf"]); +//! let mut runtime = RuntimeConfig::default() +//! runtime.pathset(["watchexec.conf"]); //! //! let conf = YourConfigFormat::load_from_file("watchexec.conf").await?; //! conf.apply(&mut runtime); //! -//! let we = Watchexec::new(init.build().unwrap(), runtime.build().unwrap()).unwrap(); +//! let we = Watchexec::new(init.build().unwrap(), runtime.clone()).unwrap(); //! let w = we.clone(); //! //! let c = config.clone(); @@ -34,7 +34,7 @@ //! let conf = YourConfigFormat::load_from_file("watchexec.conf").await?; //! //! conf.apply(&mut runtime); -//! w.reconfigure(runtime.build().unwrap()); +//! w.reconfigure(runtime.clone()); //! // tada! self-reconfiguring watchexec on config file change! //! } //! }); diff --git a/lib/tests/error_handler.rs b/lib/tests/error_handler.rs index 88221c9..21c55e5 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, RuntimeConfigBuilder}, + config::{InitConfigBuilder, RuntimeConfig}, Watchexec, }; @@ -18,7 +18,7 @@ async fn main() -> color_eyre::eyre::Result<()> { })) .build()?; - let runtime = RuntimeConfigBuilder::default().build()?; + let runtime = RuntimeConfig::default(); let wx = Watchexec::new(init, runtime)?; wx.main();