# Rust Crates (v5)

> Use jscpd's Rust crates for custom integrations.

## Installation

Add to your `Cargo.toml`:

```toml [Cargo.toml]
[dependencies]
cpd-finder = "0.1"
```

Or individual crates:

```toml [Cargo.toml]
[dependencies]
cpd-core = "0.1"
cpd-tokenizer = "0.1"
cpd-reporter = "0.1"
```

## cpd-core

The core Rabin-Karp rolling hash detection algorithm.

```rust
use cpd_core::detect;

// Detect clones from tokenized input
```

## cpd-tokenizer

Source code tokenizer with OXC-based JS/TS/JSX/TSX tokenization and generic line-based tokenization for 223 other formats.

```rust
use cpd_tokenizer::tokenize;

// Tokenize source code into detection-ready format
```

## cpd-finder

Full orchestration pipeline — file walking, tokenization, detection, and statistics.

```rust
use cpd_finder::orchestrate;

fn main() {
    let result = orchestrate(&["./src".into()], &Default::default());
    println!("Found {} clones", result.statistics.total_clones);
    println!("Duplication: {:.1}%", result.statistics.total_percentage);
}
```

## cpd-reporter

13 built-in reporters: console, console-full, json, xml, csv, html, markdown, sarif, ai, badge, xcode, threshold, silent.

## Features

- **Pure Rust** — no external runtime required
- **Parallel detection** — uses `rayon` for detection across format groups
- **OXC tokenization** — fast, accurate JS/TS/JSX/TSX parsing
- **gitoxide blame** — in-process git blame (no shelling out to `git`)
- **Cross-format detection** — Vue SFC, Svelte, Astro, Markdown

## v4 Node.js Packages

If you're using v4 (TypeScript), the equivalent packages are:

<table>
<thead>
  <tr>
    <th>
      v5 Rust Crate
    </th>
    
    <th>
      v4 npm Package
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        cpd
      </code>
    </td>
    
    <td>
      <code>
        jscpd
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        cpd-core
      </code>
    </td>
    
    <td>
      <code>
        @jscpd/core
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        cpd-tokenizer
      </code>
    </td>
    
    <td>
      <code>
        @jscpd/tokenizer
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        cpd-finder
      </code>
    </td>
    
    <td>
      <code>
        @jscpd/finder
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        cpd-reporter
      </code>
    </td>
    
    <td>
      <code>
        @jscpd/html-reporter
      </code>
      
      , <code>
        @jscpd/badge-reporter
      </code>
      
      , <code>
        @jscpd/sarif-reporter
      </code>
    </td>
  </tr>
</tbody>
</table>

See the [Migration Guide](/getting-started/migration) for details on upgrading from v4 packages.
