Scribe Core
Core types, utilities, and foundational components for the Scribe code analysis library.
Overview
scribe-core provides the fundamental data structures and traits used across all other Scribe crates. It includes comprehensive error handling, file analysis types, scoring components, configuration management, and extensibility traits.
Features
- Comprehensive Error Handling: Rich error types with proper context and error chaining
- File Analysis: File metadata, language detection, and classification systems
- Scoring System: Heuristic scoring components and configurable weights
- Configuration: Flexible configuration with validation and serialization support
- Extensibility: Traits for custom analyzers, scorers, and formatters
- Utilities: Common functions for path manipulation, string processing, and more
Usage
Add this to your Cargo.toml:
[]
= "0.1.0"
Basic usage:
use ;
// Create a default configuration
let config = default;
// Detect programming language from file extension
let language = from_extension;
assert_eq!;
// Work with scoring components
let mut scores = zero;
scores.doc_score = 0.8;
scores.import_score = 0.6;
let weights = default;
scores.compute_final_score;
println!;
Key Types
Error Handling
ScribeError: Comprehensive error type for all Scribe operationsResult<T>: Type alias forstd::result::Result<T, ScribeError>
File Analysis
FileInfo: Complete file metadata and analysis resultsLanguage: Programming language detection and classificationFileType: File type classification (source, test, documentation, etc.)RenderDecision: Include/exclude decisions for files
Scoring System
ScoreComponents: Individual heuristic score componentsHeuristicWeights: Configurable weights for scoringRepositoryInfo: Repository-level statistics and metadata
Configuration
Config: Main configuration structureFeatureFlags: Enable/disable experimental features- Various sub-configurations for filtering, analysis, performance, etc.
Traits for Extensibility
FileAnalyzer: Custom file analysis implementationsHeuristicScorer: Custom scoring algorithmsOutputFormatter: Custom output formatsCacheStorage: Custom caching implementations
Architecture
The crate is organized into several modules:
error: Comprehensive error types and handlingfile: File metadata and analysis typestypes: Core data structures and scoring componentsconfig: Configuration managementtraits: Extensibility traits and abstractionsutils: Common utility functions
Memory Safety and Performance
Scribe Core is built with Rust's ownership principles in mind:
- Zero-cost abstractions: Efficient implementations without runtime overhead
- Memory safety: Compile-time guarantees prevent common bugs
- Thread safety: Safe concurrent operations where appropriate
- Resource efficiency: Minimal memory allocations in hot paths
Testing
Run the test suite:
Run benchmarks:
Contributing
This crate serves as the foundation for the entire Scribe ecosystem. When adding new functionality:
- Ensure comprehensive error handling using
ScribeError - Add proper documentation and examples
- Include unit tests for all new functionality
- Consider thread safety and performance implications
- Follow existing naming conventions and patterns
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.