qubit-redact 0.8.1

Rule-driven redaction for fields, diagnostics, HTTP data, and Rust domain objects
Documentation
// =============================================================================
//    Copyright (c) 2026 Haixing Hu.
//
//    SPDX-License-Identifier: Apache-2.0
//
//    Licensed under the Apache License, Version 2.0.
// =============================================================================
//! Scalar leaf capability for primitive values and transparent newtypes.

use std::borrow::Cow;

#[cfg(feature = "bigdecimal")]
use bigdecimal::BigDecimal;

use super::RedactLevelValue;

/// A single scalar representation usable with an explicit redaction level.
///
/// Derive this trait for a one-field struct whose field is also a scalar.
/// Containers are level-capable but are not scalars. This capability does not
/// choose a sensitivity or implement Debug, Display, or ordinary Serialize.
/// Implementations should be generated by `#[derive(RedactScalar)]`.
///
/// # Examples
///
/// ```
/// # #[cfg(feature = "derive")] {
/// use qubit_redact::{Redact, RedactScalar, Redactor};
/// #[derive(RedactScalar)]
/// # #[redact(crate = qubit_redact)]
/// struct Id(u64);
/// #[derive(Redact)]
/// # #[redact(crate = qubit_redact)]
/// struct Event {
///     #[redact(level = "secret")]
///     id: Id,
/// }
/// let event = Event { id: Id(42) };
/// assert!(Redactor::standard().redact_text(&event).text().as_str().contains("<redacted>"));
/// # }
/// ```
pub trait RedactScalar: RedactLevelValue {
    // empty
}

/// Declares the primitive leaves that transparent scalar newtypes may wrap.
macro_rules! scalar {
    ($($ty:ty),+ $(,)?) => { $(impl RedactScalar for $ty {})+ };
}

scalar!(
    String,
    str,
    char,
    bool,
    i8,
    i16,
    i32,
    i64,
    i128,
    isize,
    u8,
    u16,
    u32,
    u64,
    u128,
    usize,
    f32,
    f64,
    Cow<'_, str>
);
impl<T: RedactScalar + ?Sized> RedactScalar for &T {}
#[cfg(feature = "bigdecimal")]
impl RedactScalar for BigDecimal {}