| Crates.io | raz-core |
| lib.rs | raz-core |
| version | 0.2.4 |
| created_at | 2025-07-02 21:30:14.436884+00 |
| updated_at | 2025-07-07 09:27:25.719835+00 |
| description | Universal command generator for Rust projects - Core library with stateless file analysis and cursor-aware execution |
| homepage | https://github.com/codeitlikemiley/raz |
| repository | https://github.com/codeitlikemiley/raz |
| max_upload_size | |
| id | 1735612 |
| size | 843,087 |
Core library for RAZ (Rust Action Zapper) - Universal command generator for Rust projects.
use raz_core::{RazCore, Position};
use std::path::Path;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let raz = RazCore::new()?;
let file_path = Path::new("src/lib.rs");
let cursor = Some(Position { line: 24, column: 0 }); // 0-based
// Generate commands with universal detection
let commands = raz.generate_universal_commands(file_path, cursor).await?;
for command in commands {
println!("Command: {}", command.label);
println!("Executable: {}", command.command);
println!("Args: {:?}", command.args);
}
Ok(())
}
use raz_core::{FileDetector, FileExecutionContext, FileType};
let context = FileDetector::detect_context(&file_path, cursor)?;
match context.file_type {
FileType::CargoPackage => {
// Handle cargo package
}
FileType::SingleFile => {
// Handle standalone file
}
// ... other types
}
use raz_core::providers::{ProviderRegistry, CargoProvider, DioxusProvider};
let mut registry = ProviderRegistry::new();
registry.register(Box::new(CargoProvider::new()));
registry.register(Box::new(DioxusProvider::new()));
let commands = registry.generate_commands(&context, cursor)?;
This example shows how raz-core integrates with other RAZ crates:
use raz_core::{RazCore, Position};
use raz_override::{OverrideSystem, SmartOverrideParser};
use raz_validation::{ValidationEngine, ValidationLevel};
use raz_config::{GlobalConfig, EffectiveConfig};
use std::path::Path;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load configuration
let config = GlobalConfig::load()?;
// Initialize core with config
let raz = RazCore::new()?;
// Generate commands
let file_path = Path::new("src/lib.rs");
let cursor = Some(Position { line: 24, column: 0 });
let commands = raz.generate_universal_commands(file_path, cursor).await?;
// Get the first command
if let Some(mut cmd) = commands.into_iter().next() {
// Apply saved overrides
let override_system = OverrideSystem::new(Path::new("."))?;
let context = override_system.get_function_context(file_path, 24, Some(0))?;
if let Some(saved_override) = override_system.resolve_override(&context)? {
cmd.apply_override(&saved_override);
}
// Validate options
let validator = ValidationEngine::new();
for arg in &cmd.args {
if let Err(e) = validator.validate_option(&cmd.command, arg, None) {
eprintln!("Warning: {}", e);
}
}
println!("Executing: {} {}", cmd.command, cmd.args.join(" "));
}
Ok(())
}
RazCore: Main entry point for command generationPosition: Cursor position (line, column) - 0-based indexingFileExecutionContext: Analysis result of a Rust fileExecutableCommand: Generated command with environment, args, and metadatagenerate_universal_commands(): Main command generation with automatic override loadingFileDetector::detect_context(): Analyze file type and structureSmartOverrideParser::parse(): Parse override stringsOverrideSystem::resolve_override(): Load saved overridesRAZ can detect and execute any Rust file pattern:
| Pattern | Example | Command Generated |
|---|---|---|
| Main Binary | src/main.rs |
cargo run --bin project |
| Library | src/lib.rs |
cargo test --lib |
| Integration Test | tests/common.rs |
cargo test --test common |
| Unit Test | src/lib.rs:25:1 |
cargo test -- tests::my_test --exact |
| Example | examples/demo.rs |
cargo run --example demo |
| Benchmark | benches/perf.rs |
cargo bench --bench perf |
| Build Script | build.rs |
Direct execution |
| Cargo Script | script.rs |
cargo +nightly -Zscript script.rs |
| Standalone | /tmp/hello.rs |
rustc hello.rs && ./hello |
| Standalone Test | /tmp/test.rs:10:1 |
rustc --test test.rs && ./test my_test |
RAZ recognizes all common test macros:
#[test] - Standard test#[tokio::test] - Async runtime tests#[async_std::test] - Alternative async tests#[test_case(...)] - Parameterized tests#[bench] - BenchmarksRAZ works with:
#!/usr/bin/env -S cargo +nightly -Zscript