Skip to main content

RecordTransform

Enum RecordTransform 

Source
pub enum RecordTransform {
    Flatten {
        separator: String,
    },
    RenameKeys {
        pattern: String,
        replacement: String,
    },
    KeysCase {
        mode: KeyCaseMode,
    },
    Select {
        fields: Vec<String>,
    },
    Drop {
        fields: Vec<String>,
    },
    Set {
        values: Map<String, Value>,
    },
    RenameField {
        fields: HashMap<String, String>,
    },
    Cast {
        fields: HashMap<String, CastType>,
        on_error: CastOnError,
    },
    Redact {
        fields: Vec<String>,
        mask: Value,
    },
    ValueCase {
        fields: Vec<String>,
        mode: ValueCaseMode,
    },
    SpellSymbols {
        extra: HashMap<String, String>,
        separator: String,
    },
    Custom(Arc<dyn Fn(Value) -> Value + Send + Sync>),
}
Expand description

A transformation applied to every record fetched by a source (e.g. the REST source’s RestStream).

Transforms are applied in the order they are added via the owning source’s configuration (e.g. RestStreamConfig::add_transform).

The three built-in variants are each guarded by a Cargo feature flag (all enabled by default — see module-level docs). RecordTransform::Custom is always available and accepts any closure.

Variants§

§

Flatten

Available on crate feature transform-flatten only.

Flatten nested JSON objects into a single-level map.

Nested key paths are joined with separator. Arrays are left as-is.

Requires feature transform-flatten (default).

§Example

{"user": {"id": 1, "addr": {"city": "NYC"}}}  →  (separator = "__")
{"user__id": 1, "user__addr__city": "NYC"}

Fields

§separator: String
§

RenameKeys

Available on crate feature transform-rename-keys only.

Apply a single regex substitution to every key in the record.

Keys in nested objects and objects inside arrays are also renamed recursively. pattern is a Rust regex; replacement may reference capture groups with $1, ${name}, etc. Chain multiple RenameKeys transforms for multi-step pipelines.

Requires feature transform-rename-keys (default).

§Example

pattern = r"^_sdc_", replacement = ""   →   strip "_sdc_" prefix

Fields

§pattern: String
§replacement: String
§

KeysCase

Available on crate feature transform-keys-case only.

Re-case every key in the record according to mode.

Tokenises each key on whitespace, _, -, dropped punctuation, and lower→upper transitions, then re-joins in the requested convention. Walks recursively into nested objects and arrays. Two distinct keys that re-case to the same name error rather than silently overwriting.

Requires feature transform-keys-case (default).

InputSnakeCamelPascalKebabScreamingSnake
"First Name""first_name""firstName""FirstName""first-name""FIRST_NAME"
"last-name""last_name""lastName""LastName""last-name""LAST_NAME"
"camelCase""camel_case""camelCase""CamelCase""camel-case""CAMEL_CASE"

Fields

§

Select

Available on crate feature transform-select only.

Keep only the listed top-level fields on each record; remove the rest.

Missing fields are silently skipped (they don’t introduce nulls). Non-object records pass through unchanged.

Requires feature transform-select.

Fields

§fields: Vec<String>
§

Drop

Available on crate feature transform-drop only.

Remove the listed top-level fields from each record.

Missing fields are silently skipped. Non-object records pass through.

Requires feature transform-drop.

Fields

§fields: Vec<String>
§

Set

Available on crate feature transform-set only.

Insert or overwrite top-level fields on each record with constant values.

Existing fields with the same name are overwritten. Non-object records pass through unchanged.

Requires feature transform-set.

Fields

§values: Map<String, Value>
§

RenameField

Available on crate feature transform-rename-field only.

Exact-name rename of one or more top-level fields.

Unlike RecordTransform::RenameKeys (regex, recursive), this only touches exact top-level keys. Missing source fields are silently skipped. If a target name already exists on the record, the rename errors rather than silently overwriting.

Requires feature transform-rename-field.

Fields

§fields: HashMap<String, String>

Map of old_name -> new_name.

§

Cast

Available on crate feature transform-cast only.

Coerce per-field types on each record.

Each named field is converted to the matching CastType. The CastOnError policy controls failure behaviour. Missing fields are silently skipped (no nulls introduced).

Requires feature transform-cast.

Fields

§on_error: CastOnError
§

Redact

Available on crate feature transform-redact only.

Replace each listed field’s value with a constant mask.

Missing fields are silently skipped (no mask inserted). Default mask is "***" when constructed from CLI config.

Requires feature transform-redact.

Fields

§fields: Vec<String>
§mask: Value
§

ValueCase

Available on crate feature transform-value-case only.

Lowercase / uppercase / trim string values on listed fields.

Non-string field values pass through unchanged. Missing fields are silently skipped.

Requires feature transform-value-case.

Fields

§fields: Vec<String>
§

SpellSymbols

Available on crate feature transform-spell-symbols only.

Recursively spell out symbols inside every key with their word equivalents (%percent, #number, $dollar, …).

Built-in defaults cover the common ASCII symbols (see default_symbol_map); extra adds or overrides entries. Each replacement is surrounded by separator (default " ") so a chained RecordTransform::KeysCase picks up the word boundary. Keys are walked recursively into nested objects and arrays, mirroring the existing key-shape transforms. Two distinct keys that collapse to the same name error rather than silently overwriting.

Requires feature transform-spell-symbols.

§Example

{"% sold": 1, "C# courses": 2}
  →  (defaults, separator=" ")
{" percent  sold": 1, "C number  courses": 2}

Fields

§extra: HashMap<String, String>

Additional mappings (merged on top of default_symbol_map; entries with the same from override the default).

§separator: String

Inserted around each replacement so word boundaries survive a downstream keys_case step. Default " ".

§

Custom(Arc<dyn Fn(Value) -> Value + Send + Sync>)

A user-supplied transformation function.

The function receives each record as a Value and returns the (possibly modified) record. Construct one with RecordTransform::custom.

Always available — not guarded by any feature flag.

Implementations§

Source§

impl RecordTransform

Source

pub fn custom<F>(f: F) -> Self
where F: Fn(Value) -> Value + Send + Sync + 'static,

Create a custom transform from any function or closure.

The closure receives each record as a Value and must return a Value (the transformed record). It is called once per record and may perform any manipulation — adding fields, removing fields, renaming, type coercion, etc.

Custom transforms are always available regardless of feature flags.

§Example
use faucet_core::RecordTransform;
use serde_json::{Value, json};

// Inject a constant "source" field into every record.
let stamp = RecordTransform::custom(|mut record| {
    if let Value::Object(ref mut map) = record {
        map.insert("_source".to_string(), json!("my-api"));
    }
    record
});

Trait Implementations§

Source§

impl Clone for RecordTransform

Source§

fn clone(&self) -> Self

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 RecordTransform

Source§

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

Formats the value using the given formatter. 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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more