> ## Documentation Index
> Fetch the complete documentation index at: https://docs.datafog.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Rust

> Rust functions, configuration types, results, and provider-backed operations.

```bash theme={null}
cargo add datafog-core
```

```rust theme={null}
use datafog_core::*;
```

## Stateless operations

### `scan`

```rust theme={null}
pub fn scan(text: &str) -> Vec<Finding>
```

Scan text with the default scan configuration.

### `scan_with_config`

```rust theme={null}
pub fn scan_with_config(text: &str, config: &ScanConfig) -> Vec<Finding>
```

### `transform`

```rust theme={null}
pub fn transform(
    text: &str,
    findings: &[Finding],
    config: &TransformationConfig,
) -> Result<TransformResult, PrivacyError>
```

Transform caller-supplied findings without scanning implicitly. Provider-backed
strategies return a provider-required error from this stateless function.

### `scan_and_transform`

```rust theme={null}
pub fn scan_and_transform(
    text: &str,
    config: &ScanAndTransformConfig,
) -> Result<TransformResult, PrivacyError>
```

## Primary configuration types

* `ScanConfig`
* `ScanAndTransformConfig`
* `TransformationConfig`
* `TransformationStrategy`
* `MaskConfig` and `MaskReveal`
* `PseudonymizeConfig`
* `TokenizeConfig`
* `PrivacyContext`

Rust constructors validate semantic values and return typed errors where
configuration can be invalid.

## Results

`Finding` exposes entity metadata, matched text, byte and code-point ranges,
optional confidence, and detector provenance.

`TransformResult` contains transformed `text` and ordered `transformations`.
`RestoreResult` contains restored `text` and ordered `restorations`.

For repeated UTF-16 conversions on the same string, reuse
`TextIndex::new(text)` and call its `utf16_range(byte_range)` method. It accepts
overlapping or unordered ranges, validates UTF-8 boundaries, and returns the
same ranges and errors as the standalone `utf16_range` helper. The index borrows
the string and builds sparse checkpoints as needed.

## Provider-backed manager

`PrivacyManager<P, T>` composes key and token provider capabilities.

```rust theme={null}
let manager = PrivacyManager::new(key_provider)
    .with_token_provider(token_provider);
```

Use:

* `transform` or `scan_and_transform` for key-backed pseudonymization;
* `transform_with_context` or `scan_and_transform_with_context` when
  tokenization may be selected;
* `restore` for authorized token restoration.

Implement the `KeyProvider` and `TokenProvider` traits in application code.
DataFog Core ships no cloud-, vault-, or database-specific provider.

For exact public definitions, see the
[crate source](https://github.com/DataFog/datafog-core/blob/main/crates/core/src/lib.rs).

## Structured JSON and PERSON fields

The `datafog_core::structured` module exposes `discover_fields`, `scan`,
`transform`, and `scan_and_transform`. Use `StructuredScanConfig::default()`
for automatic discovery or `structured::parse_scan_config` for explicit mappings.
`PrivacyManager` adds `transform_structured`, `scan_and_transform_structured`,
and `restore_structured` with the existing provider and scope contracts.

Paths are JSON Pointers. All ranges, including JavaScript UTF-16 ranges,
address the decoded string at that path. See [person-field discovery](/guides/person-discovery)
for aliases, policy configuration, input limits, and examples.
