avila-atom
Atomic Computational Structures - High-performance fundamental data structures built from first principles.
Features
- Zero-cost abstractions - No runtime overhead vs manual implementation
- Memory efficiency - Contiguous allocation for optimal cache locality
- Compile-time optimization - Monomorphization enables aggressive inlining
- no_std compatible - Works in embedded and OS development contexts
Data Structures
Core Types
-
Option<T>- Optional value (presence/absence)- Zero-cost abstraction with enum-based representation
- Null pointer optimization for references
-
Result<T, E>- Result type (success/failure)- Tagged union for error handling
- Zero-cost compared to manual error codes
-
DynamicArray<T>- Growable contiguous array- O(1) amortized push with geometric growth
- 24 bytes header (ptr + len + capacity)
-
AssociativeArray<K, V>- Key-value storagestd: HashMap with O(1) average lookupno_std: BTreeMap with O(log n) lookup
-
StringBuffer- UTF-8 encoded string- Guaranteed valid UTF-8 at all times
- Efficient growable capacity
Advanced Types
-
FixedArray<T, N>- Stack-allocated fixed-size array- Zero heap allocation
- Compile-time size known
-
SmallString- Small string optimization- Stores ≤23 bytes inline (no heap)
- Automatic heap promotion for larger strings
Usage
Add to your Cargo.toml:
[]
= "0.2"
Examples
use ;
// Dynamic array with type inference
let mut numbers = new;
numbers.push;
numbers.push;
numbers.push;
// Map with convenient macro
use map;
let config = map! ;
// UTF-8 string buffer
let mut text = from;
text.push_str;
assert_eq!; // UTF-8 byte count
Macros
use ;
// Map with capacity pre-allocation
let m = map! ;
// Dynamic array
let v = list!;
// Fixed-size stack array
let arr = array!;
assert_eq!;
Performance Characteristics
| Operation | Complexity | Notes |
|---|---|---|
DynamicArray::push |
O(1) amortized | Geometric growth (2x) |
DynamicArray::get |
O(1) | Direct index access |
AssociativeArray::get |
O(1) avg / O(log n) | HashMap / BTree |
StringBuffer::push_str |
O(n) | UTF-8 validation required |
FixedArray operations |
O(1) | Stack-allocated, inlined |
Compile-Time Guarantees
use static_assert_size;
// Verify structure sizes for ABI compatibility
static_assert_size!; // Two pointers on 64-bit
no_std Support
Disable default features and enable alloc:
[]
= { = "0.2", = false }
Note: AssociativeArray falls back to BTreeMap in no_std mode.
Architecture
Built following the Ávila Engineering Philosophy:
- Stack-preferred - Minimize heap allocations
- Zero dependencies - Built from Rust core types
- Performance-first - Optimized for modern CPU architectures
- Type-safe - Compile-time guarantees prevent runtime errors
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.
Contributing
Contributions are welcome! Please ensure:
- All tests pass (
cargo test) - Code is formatted (
cargo fmt) - No clippy warnings (
cargo clippy) - Documentation is updated
Part of the Ávila Computational Stack - Building high-performance systems from first principles.