ryo-source 0.1.0

High-speed Rust AST manipulation engine
Documentation

ryo-source

crates.io docs.rs License: MIT OR Apache-2.0

Status: stable. Part of the ryo 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

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:

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:

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 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 or MIT at your option.