Skip to content

Rust

Native Regex since v1.0

๐Ÿฆ€ Tracks every pub and pub(crate) declaration. Strips strings and comments first to kill false positives.

.rs

What gets detected

The public surface spec-sync tracks for Rust.

  • pub fn / pub async fn / pub unsafe fn
  • pub struct / pub enum / pub trait
  • pub type / pub const / pub static / pub mod
  • pub(crate) items

Detection rules

Public item declarations

Matches pub (or pub(crate)) followed by any of: fn, struct, enum, trait, type, const, static, mod. Handles async and unsafe modifiers.

pub fn create_auth(config: Config) -> Auth {}
pub struct AuthService {}
pub enum AuthStatus { Active, Expired }
pub trait Authenticator {}
pub type Token = String;
pub const DEFAULT_TTL: u64 = 3600;
pub static INSTANCE: Lazy<Auth> = Lazy::new(|| Auth::new());
pub mod utils;

pub(crate) items

Crate-internal public items are also captured, since they represent the module's API surface within the crate.

pub(crate) fn internal_fn() {}
pub(crate) struct InternalStruct {}

String literal stripping

Raw strings (r#"..."#), regular strings, and char literals are stripped before regex matching to prevent false positives from pub declarations inside string data.

// This pub fn inside a string will NOT be captured:
let test_data = r#"pub fn fake_fn() {}"#;

// This is the real export:
pub fn real_fn() {}

Example: spec & source

The *.spec.md contract on the left, the Rust source it documents on the right. spec-sync matches the two.

Spec (*.spec.md)

---
module: auth
version: 1
status: stable
files:
  - src/auth.rs
---

## Purpose

Handles JWT-based authentication.

## Public API

| Item | Kind | Description |
|------|------|-------------|
| `create_auth` | fn | Creates a new Auth instance |
| `AuthService` | struct | Auth service type |
| `AuthStatus` | enum | Active or Expired states |
| `DEFAULT_TTL` | const | Default session TTL in seconds |

## Change Log

| Date | Change |
|------|--------|
| 2026-01-01 | Initial |

Source

pub fn create_auth(config: Config) -> Auth {
    Auth::new(config)
}

pub struct AuthService {
    db: Database,
}

pub enum AuthStatus {
    Active,
    Expired,
}

pub const DEFAULT_TTL: u64 = 3600;

Test-file patterns

Files matching these are excluded from the detected surface.

Pattern Explanation
**/*_test.rs Test-only source files: auto-excluded
#[cfg(test)] mod tests { ... } Inline test modules: exports inside are excluded

Caveats

  • Procedural macros that generate pub items (e.g. #[derive], custom macros) are not detected.
  • Re-exports via pub use are not captured as distinct symbols.
  • Items inside conditional compilation blocks (#[cfg(...)]) are included unless the block is #[cfg(test)].

Related languages