Skip to main content

SensitiveValue

Trait SensitiveValue 

Source
pub trait SensitiveValue: Sized {
    // Required methods
    fn as_str(&self) -> &str;
    fn from_redacted(redacted: String) -> Self;
}
Expand description

String-like payloads that can be redacted via policies.

The redaction engine treats these values as strings for the purpose of policy application. Scalar values (numbers, booleans, chars) are not SensitiveValue and instead redact to their defaults via #[sensitive] and map_scalar.

§Relationship with SensitiveType

  • SensitiveValue: A type that is sensitive data (String, custom newtypes)
  • SensitiveType: A type that contains sensitive data (structs, enums)

Use #[sensitive(Classification)] on fields of SensitiveValue types. Use #[sensitive] on fields of SensitiveType types to walk into them.

§Foreign string-like types

If the sensitive field type comes from another crate, you cannot implement SensitiveValue for it directly (Rust’s orphan rules). The recommended pattern is to define a local newtype in your project and implement SensitiveValue for that wrapper.

from_redacted is not required to preserve the original representation; it only needs to construct a value that corresponds to the redacted string returned by the applied policy.

Required Methods§

Source

fn as_str(&self) -> &str

Returns a read-only view of the sensitive value.

Source

fn from_redacted(redacted: String) -> Self

Reconstructs the value from a redacted string.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl SensitiveValue for Cow<'_, str>

Source§

fn as_str(&self) -> &str

Source§

fn from_redacted(redacted: String) -> Self

Source§

impl SensitiveValue for String

Source§

fn as_str(&self) -> &str

Source§

fn from_redacted(redacted: String) -> Self

Implementors§