From e62f313533c05f87d5973d80c5f39a8427dc2c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sat, 16 Oct 2021 19:08:35 +1300 Subject: [PATCH] Eliminate eyre from doctests too --- Cargo.lock | 40 +++++++++++++++++---------------------- lib/Cargo.toml | 2 +- lib/src/lib.rs | 21 +++++++++++++------- lib/src/signal/process.rs | 34 +++++++++++++++++++++++++++++++-- lib/src/signal/source.rs | 2 +- 5 files changed, 65 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ad50727..38ab6c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -175,9 +175,9 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] name = "bitflags" -version = "1.3.2" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "bitvec" @@ -289,7 +289,7 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95325739f550f23c4695b87632378f3738c2e95095531f45dab316678e5a4310" dependencies = [ - "nix 0.22.0", + "nix 0.22.2", "terminfo", "thiserror", "which", @@ -298,12 +298,12 @@ dependencies = [ [[package]] name = "command-group" -version = "1.0.6" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29033dd7a07be0c480c88ae8796b998d85fb2f8788c87687fff2d89af51f7da0" +checksum = "f7a8a86f409b4a59df3a3e4bee2de0b83f1755fdd2a25e3a9684c396fc4bed2c" dependencies = [ "async-trait", - "nix 0.22.0", + "nix 0.22.2", "tokio", "winapi", ] @@ -1240,22 +1240,22 @@ dependencies = [ [[package]] name = "nix" -version = "0.17.0" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50e4785f2c3b7589a0d0c1dd60285e1188adac4006e8abd6dd578e1567027363" +checksum = "f5e06129fb611568ef4e868c14b326274959aa70ff7776e9d55323531c374945" dependencies = [ "bitflags", "cc", - "cfg-if 0.1.10", + "cfg-if 1.0.0", "libc", - "void", + "memoffset", ] [[package]] name = "nix" -version = "0.22.0" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1e25ee6b412c2a1e3fcb6a4499a5c1bfe7f43e014bdce9a6b6666e5aa2d187" +checksum = "d3bb9a13fa32bc5aeb64150cd3f32d6cf4c748f8f8a417cce5d2eb976a8370ba" dependencies = [ "bitflags", "cc", @@ -2537,12 +2537,6 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" -[[package]] -name = "void" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" - [[package]] name = "vswhom" version = "0.1.0" @@ -2797,9 +2791,9 @@ dependencies = [ [[package]] name = "zbus" -version = "1.9.1" +version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2326acc379a3ac4e34b794089f5bdb17086bf29a5fdf619b7b4cc772dc2e9dad" +checksum = "e5983c3d035549ab80db67c844ec83ed271f7c1f2546fd9577c594d34c1b6c85" dependencies = [ "async-io", "byteorder", @@ -2808,7 +2802,7 @@ dependencies = [ "fastrand", "futures", "nb-connect", - "nix 0.17.0", + "nix 0.20.2", "once_cell", "polling", "scoped-tls", @@ -2820,9 +2814,9 @@ dependencies = [ [[package]] name = "zbus_macros" -version = "1.9.1" +version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a482c56029e48681b89b92b5db3c446db0915e8dd1052c0328a574eda38d5f93" +checksum = "bce54ac7b2150a2fa21ad5842a7470ce2288158d7da1f9bfda8ad455a1c59a97" dependencies = [ "proc-macro-crate 0.1.5", "proc-macro2", diff --git a/lib/Cargo.toml b/lib/Cargo.toml index d17b8e4..30edcc7 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -33,7 +33,7 @@ tracing = "0.1.26" unicase = "2.6.0" [dependencies.command-group] -version = "1.0.5" +version = "1.0.8" features = ["with-tokio"] [dependencies.git2] diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 2a39a62..0a674db 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -11,9 +11,11 @@ //! it. [`Handler`][handler::Handler]s are used to hook into watchexec at various points. The //! runtime config can be changed at any time with the [`Watchexec::reconfigure()`] method. //! +//! It's recommended to use the [miette] erroring library in applications, but all errors implement +//! [`std::error::Error`] so your favourite error handling library can of course be used. +//! //! ```no_run -//! # use color_eyre::eyre::Report; -//! # use std::convert::Infallible; +//! use miette::{IntoDiagnostic, Result}; //! use watchexec::{ //! Watchexec, //! action::{Action, Outcome}, @@ -22,7 +24,7 @@ //! }; //! //! #[tokio::main] -//! async fn main() -> Result<(), Report> { +//! async fn main() -> Result<()> { //! let mut init = InitConfig::default(); //! init.on_error(PrintDebug(std::io::stderr())); //! @@ -41,7 +43,7 @@ //! let w = w.clone(); //! async move { //! for event in &action.events { -//! if event.paths().any(|p| p.ends_with("/watchexec.conf")) { +//! if event.paths().any(|(p, _)| p.ends_with("/watchexec.conf")) { //! let conf = YourConfigFormat::load_from_file("watchexec.conf").await?; //! //! conf.apply(&mut c); @@ -58,18 +60,23 @@ //! )); //! //! Ok(()) -//! # as Result<_, Infallible> +//! # as std::result::Result<_, MietteStub> //! } //! }); //! -//! we.main().await?; +//! we.main().await.into_diagnostic()?; //! Ok(()) //! } //! # struct YourConfigFormat; //! # impl YourConfigFormat { -//! # async fn load_from_file(_: &str) -> Result { Ok::<_, Infallible>(Self) } +//! # async fn load_from_file(_: &str) -> std::result::Result { Ok(Self) } //! # fn apply(&self, _: &mut RuntimeConfig) { } //! # } +//! # use miette::Diagnostic; +//! # use thiserror::Error; +//! # #[derive(Debug, Error, Diagnostic)] +//! # #[error("stub")] +//! # struct MietteStub; //! ``` //! //! Alternatively, one can use the modules exposed by the crate and the external crates such as diff --git a/lib/src/signal/process.rs b/lib/src/signal/process.rs index ca379bb..116e89e 100644 --- a/lib/src/signal/process.rs +++ b/lib/src/signal/process.rs @@ -85,10 +85,25 @@ pub enum SubSignal { /// # // we don't have a direct nix dependency, so we fake it... rather horribly /// # mod nix { pub mod sys { pub mod signal { /// # #[cfg(unix)] pub use command_group::Signal; - /// # #[cfg(not(unix))] #[repr(i32)] pub enum Signal { SIGABRT = 7 } + /// # #[cfg(not(unix))] #[repr(i32)] pub enum Signal { SIGABRT = 6 } /// # } } } + /// use watchexec::signal::process::SubSignal; /// use nix::sys::signal::Signal; - /// assert_eq!(SubSignal::Custom(7), SubSignal::from(Signal::SIGABRT as _)); + /// assert_eq!(SubSignal::Custom(6), SubSignal::from(Signal::SIGABRT as i32)); + /// ``` + /// + /// On Unix the [`from_nix`][SubSignal::from_nix] method should be preferred if converting from + /// Nix's `Signal` type: + /// + /// ``` + /// # #[cfg(unix)] + /// # { + /// # // we don't have a direct nix dependency, so we fake it... rather horribly + /// # mod nix { pub mod sys { pub mod signal { pub use command_group::Signal; } } } + /// use watchexec::signal::process::SubSignal; + /// use nix::sys::signal::Signal; + /// assert_eq!(SubSignal::Custom(6), SubSignal::from_nix(Signal::SIGABRT)); + /// # } /// ``` Custom(i32), } @@ -138,6 +153,21 @@ impl From for SubSignal { } } +impl From for SubSignal { + fn from(raw: i32) -> Self { + match raw { + 1 => Self::Hangup, + 2 => Self::Interrupt, + 3 => Self::Quit, + 9 => Self::ForceStop, + 10 => Self::User1, + 12 => Self::User2, + 15 => Self::Terminate, + _ => Self::Custom(raw), + } + } +} + impl FromStr for SubSignal { type Err = SignalParseError; diff --git a/lib/src/signal/source.rs b/lib/src/signal/source.rs index 5444308..1094e34 100644 --- a/lib/src/signal/source.rs +++ b/lib/src/signal/source.rs @@ -76,7 +76,7 @@ pub enum MainSignal { /// /// ```no_run /// use tokio::sync::mpsc; -/// use watchexec::signal::worker; +/// use watchexec::signal::source::worker; /// /// #[tokio::main] /// async fn main() -> Result<(), Box> {