Skip to main content

DataMasker

Struct DataMasker 

Source
pub struct DataMasker;

Implementations§

Source§

impl DataMasker

Source

pub fn apply(rule: &MaskingRule, value: &str) -> String

Applies the given masking rule to value. The implementation is Unicode-safe (works on char boundaries rather than byte slices) and never panics: inputs shorter than the rule’s required visible prefix return a sensible fallback (the original value, or "***" when even the original cannot be safely revealed).

Source

pub fn apply_many(rules: &[MaskingRule], value: &str) -> String

Applies a sequence of rules to the same value, in order.

Useful for stacked masking (e.g. first mask the whole phone, then apply a custom prefix/suffix rule). Each rule is applied to the output of the previous one.

Source

pub fn mask_map( rules: &HashMap<String, MaskingRule>, data: &HashMap<String, String>, ) -> HashMap<String, String>

Masks specific fields of a HashMap<String, String> in place, returning a new map with only the masked fields replaced.

Fields whose rule is None are copied through unchanged. Fields not present in rules are also copied through, so callers can pass a partial rule set without losing data.

Source

pub fn mask_json(rules: &HashMap<String, MaskingRule>, json: &str) -> String

Masks a JSON object string by field name.

rules maps field names to masking rules. Only top-level fields are matched (nested objects are left untouched); non-JSON input is returned unchanged so callers can rely on this being lossless for malformed payloads.

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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.