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:
parent
b4ead7f5fb
commit
05afb141b6
|
@ -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())?;
|
||||||
|
|
|
@ -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.
|
||||||
///
|
///
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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>(())
|
||||||
|
|
Loading…
Reference in New Issue