ryo-source 0.1.0

High-speed Rust AST manipulation engine
Documentation
# ryo-source

[![crates.io](https://img.shields.io/crates/v/ryo-source.svg)](https://crates.io/crates/ryo-source)
[![docs.rs](https://docs.rs/ryo-source/badge.svg)](https://docs.rs/ryo-source)
[![License: MIT OR Apache-2.0](https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue.svg)](#license)

> **Status:** stable. Part of the [ryo]https://github.com/ynishi/ryo-rs workspace —
> AST-centric Rust programming for AI agents.

High-speed Rust AST manipulation engine. Provides two complementary AST
representations: **`RustAST`** for full-fidelity manipulation (preserves
spans, supports code generation) and **`PureFile`** for thread-safe parallel
processing (span-free, `Send + Sync + Arc`-shareable, serializable).

## Install

```sh
cargo add ryo-source
```

Optional features:

| Feature | Effect |
|---|---|
| `parallel` | Enables `rayon`-backed parallel transforms |
| `serde` | Derives `Serialize` / `Deserialize` on `PureFile` and friends |
| `schemars` | JSON Schema generation for `PureFile` |
| `test-utils` | Test helpers (`tempfile` workspace) |

## Quickstart

Remove unused imports with `RustAST`:

```rust
use ryo_source::RustAST;

let mut ast = RustAST::parse("use std::io;\nfn main() {}").unwrap();
let removed = ast.remove_unused_imports();
assert_eq!(removed.len(), 1);
assert!(!ast.to_string_pretty().contains("use std::io"));
```

Share an AST across threads with `PureFile`:

```rust
use std::sync::Arc;
use std::thread;
use ryo_source::PureFile;

let pure = PureFile::from_source("fn foo() {} fn bar() {}").unwrap();
let shared = Arc::new(pure);

let s1 = Arc::clone(&shared);
let handle = thread::spawn(move || s1.functions().len());
assert_eq!(handle.join().unwrap(), 2);
```

## API Summary

| Type | Purpose |
|---|---|
| `RustAST` | Full-fidelity AST wrapping `syn::File` — spans preserved, code-gen capable, **not** `Send + Sync` |
| `PureFile` | Span-stripped AST — `Send + Sync`, `Arc`-shareable, serializable, ~10% size of `RustAST` |
| `PureItem` / `PureFn` / `PureStruct` / `PureImpl` / … | Owned variants of `syn` items used by `PureFile` |
| `pure::*` | Pure pattern, expression, statement, attribute, generics types |

See [the crate docs](https://docs.rs/ryo-source) for the full module index.

## Status

- API surface is considered stable for the v0.1.0 release.
- `RustAST` is for in-process editing only; cross-thread workflows should use
  `PureFile`.

## License

Licensed under either of [Apache-2.0](https://github.com/ynishi/ryo-rs/blob/main/LICENSE-APACHE)
or [MIT](https://github.com/ynishi/ryo-rs/blob/main/LICENSE-MIT) at your option.