Stop using Builder for RuntimeConfig

This commit is contained in:
Félix Saparelli 2021-08-22 20:49:24 +12:00
parent 53854d93d4
commit 6c3c06e39c
No known key found for this signature in database
GPG Key ID: B948C4BAE44FC474
4 changed files with 15 additions and 15 deletions

View File

@ -2,7 +2,7 @@ use std::time::Duration;
use tokio::time::sleep; use tokio::time::sleep;
use watchexec::{ use watchexec::{
config::{InitConfigBuilder, RuntimeConfigBuilder}, config::{InitConfigBuilder, RuntimeConfig},
Watchexec, Watchexec,
}; };
@ -19,7 +19,7 @@ async fn main() -> color_eyre::eyre::Result<()> {
})) }))
.build()?; .build()?;
let runtime = RuntimeConfigBuilder::default().build()?; let runtime = RuntimeConfig::default();
let wx = Watchexec::new(init, runtime)?; let wx = Watchexec::new(init, runtime)?;
wx.main(); wx.main();

View File

@ -1,30 +1,30 @@
use std::fmt; use std::{fmt, sync::Arc, time::Duration};
use atomic_take::AtomicTake;
use derive_builder::Builder; use derive_builder::Builder;
use crate::{error::RuntimeError, handler::Handler}; use crate::{action::Action, error::RuntimeError, handler::Handler};
/// Runtime configuration for [`Watchexec`][crate::Watchexec]. /// Runtime configuration for [`Watchexec`][crate::Watchexec].
/// ///
/// This is used both when constructing the instance (as initial configuration) and to reconfigure /// This is used both when constructing the instance (as initial configuration) and to reconfigure
/// it at runtime via [`Watchexec::reconfig()`][crate::Watchexec::reconfig()]. /// it at runtime via [`Watchexec::reconfig()`][crate::Watchexec::reconfig()].
/// ///
/// Use [`RuntimeConfigBuilder`] to build a new one, or modify an existing one. This struct is /// 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. /// marked non-exhaustive such that new options may be added without breaking change. You can make
#[derive(Builder, Clone, Debug)] /// changes through the fields directly, or use the convenience (chainable!) methods instead.
#[derive(Clone, Debug, Default)]
#[non_exhaustive] #[non_exhaustive]
pub struct RuntimeConfig { pub struct RuntimeConfig {
/// Working data for the filesystem event source. /// Working data for the filesystem event source.
/// ///
/// This notably includes the path set to be watched. /// This notably includes the path set to be watched.
#[builder(default)]
pub fs: crate::fs::WorkingData, pub fs: crate::fs::WorkingData,
/// Working data for the action processing. /// Working data for the action processing.
/// ///
/// This is the task responsible for scheduling the actions in response to events, applying the /// This is the task responsible for scheduling the actions in response to events, applying the
/// filtering, etc. /// filtering, etc.
#[builder(default)]
pub action: crate::action::WorkingData, pub action: crate::action::WorkingData,
} }

View File

@ -19,13 +19,13 @@
//! let init = InitConfigBuilder::default() //! let init = InitConfigBuilder::default()
//! .error_handler(PrintDebug(std::io::stderr())); //! .error_handler(PrintDebug(std::io::stderr()));
//! //!
//! let mut runtime = RuntimeConfigBuilder::default() //! let mut runtime = RuntimeConfig::default()
//! config.pathset(["watchexec.conf"]); //! runtime.pathset(["watchexec.conf"]);
//! //!
//! let conf = YourConfigFormat::load_from_file("watchexec.conf").await?; //! let conf = YourConfigFormat::load_from_file("watchexec.conf").await?;
//! conf.apply(&mut runtime); //! 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 w = we.clone();
//! //!
//! let c = config.clone(); //! let c = config.clone();
@ -34,7 +34,7 @@
//! let conf = YourConfigFormat::load_from_file("watchexec.conf").await?; //! let conf = YourConfigFormat::load_from_file("watchexec.conf").await?;
//! //!
//! conf.apply(&mut runtime); //! conf.apply(&mut runtime);
//! w.reconfigure(runtime.build().unwrap()); //! w.reconfigure(runtime.clone());
//! // tada! self-reconfiguring watchexec on config file change! //! // tada! self-reconfiguring watchexec on config file change!
//! } //! }
//! }); //! });

View File

@ -2,7 +2,7 @@ use std::time::Duration;
use tokio::time::sleep; use tokio::time::sleep;
use watchexec::{ use watchexec::{
config::{InitConfigBuilder, RuntimeConfigBuilder}, config::{InitConfigBuilder, RuntimeConfig},
Watchexec, Watchexec,
}; };
@ -18,7 +18,7 @@ async fn main() -> color_eyre::eyre::Result<()> {
})) }))
.build()?; .build()?;
let runtime = RuntimeConfigBuilder::default().build()?; let runtime = RuntimeConfig::default();
let wx = Watchexec::new(init, runtime)?; let wx = Watchexec::new(init, runtime)?;
wx.main(); wx.main();