pub enum Transform {
Reverse,
Uppercase,
Mock,
Noise,
Chaos,
Scramble,
Delete,
Synonym,
Delay(u64),
Chain(Vec<Transform>),
}Expand description
The set of token mutation strategies available at the interception layer.
Each variant describes a different way to perturb a token in the stream. The transform is applied only at odd-indexed positions (i.e., every other token, starting from index 1) unless the caller overrides the rate.
§Strategies
| Variant | Behaviour |
|---|---|
Reverse | Reverses the Unicode characters of the token: "hello" -> "olleh". |
Uppercase | Uppercases every character: "hello" -> "HELLO". |
Mock | Alternates lowercase/uppercase per character position: "hello" -> "hElLo". |
Noise | Appends one random symbol from * + ~ @ # $ %: "hello" -> "hello*". |
Chaos | Randomly picks one of Reverse, Uppercase, Mock, or Noise per token. |
Scramble | Fisher-Yates shuffles the characters: same characters, random order. |
Delete | Drops the token entirely, returning an empty string. |
Synonym | Replaces the token with a synonym from the built-in 200-entry map; passes through unchanged if no entry exists. |
Delay(ms) | Returns the token unmodified after the given delay in milliseconds. Useful for pacing experiments. |
Chain(vec) | Applies a sequence of transforms in order; label is the individual labels joined by +. |
Variants§
Reverse
Reverse the Unicode characters of the token.
Uppercase
Uppercase every character of the token.
Mock
Alternate lowercase/uppercase per character position (sPoNgEbOb case).
Noise
Append one random symbol from the noise character set.
Chaos
Randomly select one of Reverse, Uppercase, Mock, or Noise for each token.
Scramble
Shuffle the characters of the token using Fisher-Yates.
Delete
Return an empty string, effectively deleting the token from the stream.
Synonym
Replace the token with a built-in synonym; pass through unchanged if not found.
Delay(u64)
Return the token unchanged after sleeping for the given number of milliseconds.
Chain(Vec<Transform>)
Apply a sequence of transforms in order, chaining their effects.
Implementations§
Source§impl Transform
impl Transform
Sourcepub fn from_str_loose(s: &str) -> Result<Self, String>
pub fn from_str_loose(s: &str) -> Result<Self, String>
Parse a transform name (case-insensitive) or a comma-separated chain.
Recognised single names: reverse, uppercase, mock, noise, chaos,
scramble, delete, synonym, delay, delay:N (where N is milliseconds).
Comma-separated input like "reverse,uppercase" produces a Chain variant.
A single-element comma-separated string is unwrapped to the plain variant.
§Errors
Returns Err(String) if any component name is unrecognised.
Sourcepub fn apply_with_label_rng<R: Rng>(
&self,
token: &str,
rng: &mut R,
) -> (String, String)
pub fn apply_with_label_rng<R: Rng>( &self, token: &str, rng: &mut R, ) -> (String, String)
Apply the transform using the provided RNG and return (result, label).
For Chaos, the sub-transform is chosen via rng; for others the label
equals the transform name. Prefer this over apply_with_label in hot
paths to avoid per-call thread_rng() TLS lookups.
Sourcepub fn apply_rng<R: Rng>(&self, token: &str, rng: &mut R) -> String
pub fn apply_rng<R: Rng>(&self, token: &str, rng: &mut R) -> String
Apply the transform using the provided RNG.
Sourcepub fn apply_with_label(&self, token: &str) -> (String, String)
pub fn apply_with_label(&self, token: &str) -> (String, String)
Apply the transform and return (result, label). Creates a one-shot
thread_rng(); use apply_with_label_rng in hot paths.
Sourcepub fn apply_at_rate(&self, token: &str, rate: f64) -> String
pub fn apply_at_rate(&self, token: &str, rate: f64) -> String
Apply the transform to token at the given rate.
rate must be in [0.0, 1.0].
Sourcepub fn apply(&self, token: &str) -> String
pub fn apply(&self, token: &str) -> String
Apply the transform and return only the resulting string.
Convenience wrapper around apply_with_label.
Sourcepub fn apply_with_rate_check(&self, token: &str, rate: f64) -> String
pub fn apply_with_rate_check(&self, token: &str, rate: f64) -> String
Apply the transform to token, asserting that rate is valid.