From c5ddfdc0bed842d0eb11ca8db1d985dce8c74b57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Wed, 14 Jan 2026 15:45:27 -0500 Subject: [PATCH] fix: make spin dependency optional for std builds - spin is now optional, only needed for no_std (provides Once) - std builds use OnceLock, avoiding unnecessary dependency - Restore unicode-width default features (keeps CJK support) --- Cargo.toml | 5 ++--- src/eyreish/mod.rs | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5b2dece..f6221dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,10 +14,9 @@ exclude = ["images/", "tests/", "miette-derive/"] [dependencies] miette-derive = { path = "miette-derive", version = "=7.6.0", optional = true } -unicode-width = { version = "0.2.0", default-features = false } +unicode-width = "0.2.0" cfg-if = "1.0.0" -# spin is needed for no_std environments (provides Once without std) -spin = { version = "0.9", default-features = false, features = ["once"] } +spin = { version = "0.9", default-features = false, features = ["once"], optional = true } owo-colors = { version = "4.0.0", optional = true } textwrap = { version = "0.16.0", default-features = false, features = ["unicode-linebreak", "unicode-width"], optional = true } diff --git a/src/eyreish/mod.rs b/src/eyreish/mod.rs index 3667b73..c7fb697 100644 --- a/src/eyreish/mod.rs +++ b/src/eyreish/mod.rs @@ -68,7 +68,7 @@ pub type ErrorHook = #[cfg(feature = "std")] static HOOK: OnceLock = OnceLock::new(); -#[cfg(not(feature = "std"))] +#[cfg(all(not(feature = "std"), feature = "spin"))] static HOOK: spin::Once = spin::Once::new(); fn default_hook() -> ErrorHook { @@ -96,7 +96,7 @@ pub fn set_hook(hook: ErrorHook) -> Result<(), InstallError> { } /// Set the error hook. -#[cfg(not(feature = "std"))] +#[cfg(all(not(feature = "std"), feature = "spin"))] pub fn set_hook(hook: ErrorHook) -> Result<(), InstallError> { HOOK.call_once(|| hook); Ok(()) @@ -108,7 +108,7 @@ pub(crate) fn capture_handler(error: &(dyn Diagnostic + 'static)) -> Box Box { let hook = HOOK.call_once(default_hook); hook(error) @@ -126,7 +126,7 @@ pub(crate) fn capture_handler_with_location( } #[track_caller] -#[cfg(not(feature = "std"))] +#[cfg(all(not(feature = "std"), feature = "spin"))] pub(crate) fn capture_handler_with_location( error: &(dyn Diagnostic + 'static), ) -> Box {