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 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();

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 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,
}

View File

@ -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!
//! }
//! });

View File

@ -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();