Skip to main content

Redactor

Struct Redactor 

Source
pub struct Redactor { /* private fields */ }
Expand description

A fused-alternation redactor: one regex, one pass, N patterns.

See the crate-level docs for the performance model.

Implementations§

Source§

impl Redactor

Source

pub fn empty() -> Self

Construct a redactor with no patterns and the default marker. Add patterns via Self::with_pattern.

Source

pub fn with_defaults() -> Self

Construct a redactor pre-loaded with every built-in pattern: credit card, JWT, OAuth bearer, email, IPv4, AWS key.

All six patterns are fused into a single alternation regex at process start-up (via LazyLock). Subsequent calls to this constructor clone the cached Regex — construction is O(1) past the first call.

Source

pub fn with_pattern(self, pattern: &str) -> Result<Self, Error>

Append a custom regex pattern.

The pattern is validated in isolation before being fused into the combined alternation, so a compile error surfaces the specific bad pattern rather than the fused string.

§Errors

Returns regex::Error if the pattern fails to compile.

Source

pub fn marker(self, marker: impl Into<String>) -> Self

Override the replacement marker (default: "[REDACTED]").

Source

pub fn scrub(&self, log: Log) -> Log

Scrub a record in-place. Returns the (possibly modified) record for fluent chaining.

Source

pub fn apply(&self, input: &str) -> String

Apply the fused pattern to a single string.

One replace_all pass through the regex DFA replaces every match — regardless of which pattern each match originates from — with the configured marker.

Source

pub fn len(&self) -> usize

How many patterns are loaded.

Source

pub fn is_empty(&self) -> bool

Returns true if no patterns are loaded.

Trait Implementations§

Source§

impl Clone for Redactor

Source§

fn clone(&self) -> Redactor

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Redactor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Redactor

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.