| Crates.io | ass-editor |
| lib.rs | ass-editor |
| version | 0.1.1 |
| created_at | 2025-08-06 08:40:30.441737+00 |
| updated_at | 2025-08-06 08:40:30.441737+00 |
| description | High-performance, ergonomic editor layer for ASS subtitles |
| homepage | https://github.com/wiedymi/ass-rs |
| repository | https://github.com/wiedymi/ass-rs |
| max_upload_size | |
| id | 1783559 |
| size | 1,123,551 |
A high-performance, ergonomic editor layer for ASS (Advanced SubStation Alpha) subtitles, built on top of ass-core. Designed for interactive subtitle editing with zero-copy efficiency, incremental updates, and comprehensive command support.
Add to your Cargo.toml:
[dependencies]
ass-editor = "0.1"
# With additional features
ass-editor = { version = "0.1", features = ["search-index", "plugins"] }
use ass_editor::{EditorDocument, Position, Range};
// Create a new document
let mut doc = EditorDocument::from_content(r#"
[Script Info]
Title: My Subtitle
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,Arial,20,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,0,2,10,10,10,1
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:00.00,0:00:05.00,Default,,0,0,0,,Hello World
"#).unwrap();
// Basic text operations
let pos = Position::new(200);
doc.insert_at(pos, " there").unwrap();
// Undo/redo support
doc.undo().unwrap();
doc.redo().unwrap();
println!("Content: {}", doc.text());
use ass_editor::{EditorDocument, Position, Range, commands::*};
let mut doc = EditorDocument::new();
// Fluent command chaining
doc.at_pos(Position::new(0))
.insert_text("Hello ")
.and_then(|_| doc.at_pos(Position::new(6)))
.and_then(|_| doc.insert_text("World"))
.unwrap();
// Range operations
let range = Range::new(Position::new(0), Position::new(5));
doc.command()
.range(range)
.replace("Hi")
.unwrap();
assert_eq!(doc.text(), "Hi World");
use ass_editor::{EditorDocument, StyleBuilder, EventBuilder};
let mut doc = EditorDocument::from_content("[V4+ Styles]\n[Events]\n").unwrap();
// Create and apply styles
let style = StyleBuilder::new("Title")
.fontname("Arial")
.fontsize(24)
.primary_colour("&H00FFFFFF")
.build();
doc.styles()
.create(style)
.execute()
.unwrap();
// Create events with the fluent API
doc.events()
.create_dialogue()
.start_time("0:00:00.00")
.end_time("0:00:05.00")
.style("Title")
.text("Hello World")
.execute()
.unwrap();
use ass_editor::{EditorDocument, Position, Range, commands::karaoke_commands::*};
let mut doc = EditorDocument::from_content("Hello World").unwrap();
let range = Range::new(Position::new(0), Position::new(11));
// Generate karaoke timing
doc.karaoke()
.in_range(range)
.generate(50) // 50 centiseconds per syllable
.karaoke_type(KaraokeType::Fill)
.execute()
.unwrap();
// Adjust existing karaoke timing
doc.karaoke()
.in_range(range)
.adjust()
.scale(1.5) // Make 50% longer
.execute()
.unwrap();
use ass_editor::{EditorDocument, utils::search::*};
let mut doc = EditorDocument::from_content("Large subtitle script...").unwrap();
// Build search index for fast queries
doc.build_search_index().unwrap();
// Fast regex search
let results = doc.search()
.pattern(r"\\b\d+") // Find bold tags with numbers
.case_insensitive()
.execute()
.unwrap();
for result in results {
println!("Match at {}: {}", result.position(), result.text());
}
use ass_editor::{EditorSessionManager, SessionConfig};
let mut manager = EditorSessionManager::new(SessionConfig::default());
// Create multiple sessions
let session1 = manager.create_session("subtitle1.ass").unwrap();
let session2 = manager.create_session("subtitle2.ass").unwrap();
// Switch between sessions with shared resources
manager.activate_session(&session1).unwrap();
// Edit session1...
manager.activate_session(&session2).unwrap();
// Edit session2...
// Sessions share extension registry and memory pools
ass-editor uses feature flags to enable optional functionality:
minimal: Core editing with rope, arena, and stream support (no_std compatible)full: All features including std, analysis, plugins, formats, search, concurrency, serdestd: Standard library support (required for most features)analysis: Script analysis and linting integration from ass-coreplugins: Extension system with syntax highlighting and auto-completionsearch-index: FST-based advanced search indexingformats: Import/export support for SRT, WebVTT formatsserde: Serialization support for editor stateconcurrency: Multi-threading and async supportsimd: SIMD acceleration for parsing performancestream: Incremental parsing for large filesnostd: No-standard library support for embedded/WASMdev-benches: Development benchmarking# Minimal editor for lightweight integrations
ass-editor = { version = "0.1", default-features = false, features = ["minimal"] }
# Full-featured desktop editor
ass-editor = { version = "0.1", features = ["full", "simd"] }
# WASM/embedded build
ass-editor = { version = "0.1", default-features = false, features = ["minimal", "nostd"] }
# Server-side processing
ass-editor = { version = "0.1", features = ["full", "concurrency", "formats"] }
ASS-Editor is built in layers:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ User Applications โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ EditorSessionManager โ Multi-document Management โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ EditorDocument โ Single Document Editing โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Commands โ Extensions โ Events โ Search โ Validation โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ ass-core โ
โ (Zero-copy parsing & AST manipulation) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
All operations in ass-editor go through a command system that provides:
| Category | Commands | Description |
|---|---|---|
| Text | Insert, Delete, Replace | Basic text operations |
| Events | Create, Split, Merge, Timing | Event management |
| Styles | Create, Edit, Delete, Clone, Apply | Style operations |
| Tags | Insert, Remove, Replace, Wrap, Parse | Override tag handling |
| Karaoke | Generate, Split, Adjust, Apply | Karaoke timing management |
ASS-Editor provides powerful search capabilities:
Run the comprehensive test suite:
# Unit tests
cargo test
# Integration tests
cargo test --test integration
# Performance tests
cargo test --test performance_targets
# All features
cargo test --all-features
# Specific feature combinations
cargo test --no-default-features --features minimal
Run performance benchmarks:
# All benchmarks
cargo bench
# Specific benchmarks
cargo bench --bench editor_commands
cargo bench --bench search_performance
cargo bench --bench memory_usage
Expected performance on typical subtitle files:
| Operation | Target | Typical Result |
|---|---|---|
| Document creation | <5ms | ~2ms |
| Single edit | <1ms | ~0.3ms |
| Undo/redo | <1ms | ~0.2ms |
| Search (indexed) | <10ms | ~3ms |
| Session switch | <100ยตs | ~50ยตs |
Contributions are welcome! Please see the main CONTRIBUTING.md for guidelines.
# Clone the repository
git clone https://github.com/wiedymi/ass-rs.git
cd ass-rs/crates/ass-editor
# Run tests
cargo test --all-features
# Run benchmarks
cargo bench
# Check code quality
cargo clippy --all-targets --all-features -- -D warnings
cargo fmt --all -- --check
Licensed under the MIT license.
Built with โค๏ธ in Rust for subtitle editors worldwide