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)
This commit is contained in:
François Garillot 2026-01-14 15:45:27 -05:00
parent c07cab4b60
commit c5ddfdc0be
No known key found for this signature in database
GPG Key ID: E7645C6B883A1E9A
2 changed files with 6 additions and 7 deletions

View File

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

View File

@ -68,7 +68,7 @@ pub type ErrorHook =
#[cfg(feature = "std")]
static HOOK: OnceLock<ErrorHook> = OnceLock::new();
#[cfg(not(feature = "std"))]
#[cfg(all(not(feature = "std"), feature = "spin"))]
static HOOK: spin::Once<ErrorHook> = 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<dyn Rep
hook(error)
}
#[cfg(not(feature = "std"))]
#[cfg(all(not(feature = "std"), feature = "spin"))]
pub(crate) fn capture_handler(error: &(dyn Diagnostic + 'static)) -> Box<dyn ReportHandler> {
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<dyn ReportHandler> {