v-storage
A flexible storage abstraction library for the Veda platform. Provides unified interface for different storage backends including memory, LMDB, Tarantool, and remote storage.
๐ Features
- Multiple Storage Backends: Memory, LMDB, Tarantool (TTStorage), Remote storage
- Unified API: Common
Storagetrait for all backends - Three Architecture Patterns: Dynamic dispatch, generic containers, enum dispatch
- Individual Support: Native support for Veda platform Individual objects
- Zero-cost Abstractions: Compile-time optimization options with minimal overhead
- Factory Patterns: Builder, Provider, and Config patterns for easy construction
- Error Handling: Comprehensive error types and result handling
- Backward Compatibility: Support for legacy API methods
๐ฆ Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
# Optional features
= { = "0.1.0", = ["tt_2", "tokio_0_2"] }
Available Features
tt_2- Tarantool 2.x supporttt_3- Tarantool 3.x supporttokio_0_2- Tokio 0.2 runtime supporttokio_1- Tokio 1.x runtime support
๐ Quick Start
use *;
๐๏ธ Architecture
Storage Types
| Type | Description | Dispatch | Use Case |
|---|---|---|---|
| VStorage | Dynamic dispatch with trait objects | Runtime | Maximum flexibility, runtime type selection |
| VStorageGeneric | Compile-time typed containers | Static | Type safety, known storage type |
| VStorageEnum | Static dispatch through enum | Static | Applications preferring enum dispatch |
Storage Backends
- Memory Storage - In-memory HashMap-based storage
- LMDB Storage - Lightning Memory-Mapped Database
- Tarantool Storage - In-memory NoSQL database
- Remote Storage - Network-based storage client
StorageId Types
- Individuals - Main Individual objects for Veda platform
- Tickets - System tickets and tasks
- Az - Authorization and permission data
๐ Usage Examples
Basic Operations
use *;
// Create storage using Builder pattern
let storage = builder
.memory
.build?;
let mut storage = new;
// Basic operations with semantic Individual data
storage.put_value?;
storage.get_value?;
storage.remove_value?;
storage.count?;
Factory Patterns
// Builder Pattern
let storage = builder
.lmdb
.build?;
// Provider Pattern
let storage = memory;
// Config Pattern
let config = Memory;
let storage = from_config?;
Working with Individual Objects
use Individual;
let mut individual = default;
let result = storage.get_individual;
match result
Static Dispatch Usage
// Use VStorageEnum for static dispatch
let mut storage = memory;
// Batch operations with semantic Individual data
for i in 0..1000
๐ฏ Design Patterns
Strategy Pattern
Unified Storage interface allows switching between different storage implementations:
Builder Pattern
Fluent API for configuring storage:
let storage = builder
.memory
.build?;
Abstract Factory
Multiple ways to create storage instances:
// Through provider
let storage1 = memory;
// Through config
let storage2 = from_config?;
// Through builder
let storage3 = builder.memory.build?;
๐ Architecture Comparison
Theoretical dispatch overhead (in practice, database I/O dominates):
| Storage Type | Dispatch | Memory | Flexibility |
|---|---|---|---|
| VStorageEnum | Static (enum match) | Stack | Fixed set of types |
| VStorageGeneric | Static (monomorphization) | Direct | Compile-time known |
| VStorage | Dynamic (vtable) | Heap | Runtime selection |
Note: In real applications, storage backend (LMDB, Tarantool, network) dominates timing.
๐ง Configuration
Memory Storage
let storage = builder
.memory
.build?;
LMDB Storage
let storage = builder
.lmdb
.build?;
Tarantool Storage
// Requires tt_2 or tt_3 feature
let storage = builder
.tarantool
.build?;
Remote Storage
let storage = builder
.remote
.build?;
๐ Examples
The examples/ directory contains comprehensive examples:
- basic_usage.rs - Basic operations and API usage
- storage_types.rs - Comparison of different storage types
- factory_patterns.rs - Various construction patterns
- individual_operations.rs - Working with Individual objects
Run examples:
๐ ๏ธ Development
Building
# Basic build
# With all features
# Release build
Testing
# Run tests
# Run tests with features
# Run integration tests
Documentation
# Generate documentation
# Generate with examples
๐ Error Handling
The library uses comprehensive error types:
match storage.get_value
๐งช Testing
# Unit tests
# Integration tests
# Example tests
# All tests with release optimization
๐ Requirements
- Rust: 1.70 or higher
- Operating System: Linux, macOS, Windows
- Dependencies: See Cargo.toml
Optional Requirements
- LMDB: System LMDB libraries for LMDBStorage
- Tarantool: Running Tarantool instance for TTStorage
- Network: Connectivity for RemoteStorage
๐ค Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
- Clone the repository
- Install Rust 1.70+
- Run
cargo build - Run
cargo test - Check examples with
cargo run --example basic_usage
Code Style
- Use
cargo fmtfor formatting - Use
cargo clippyfor linting - Add tests for new features
- Update documentation
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Related Projects
- Veda Platform - Semantic data management platform
- v-individual-model - Individual object model
- LMDB - Lightning Memory-Mapped Database
- Tarantool - In-memory database and application server
๐ก FAQ
Q: Which storage type should I choose?
A: Use VStorageEnum for applications preferring static dispatch, VStorageGeneric for type safety with known storage types, and VStorage for maximum flexibility.
Q: Can I switch storage backends at runtime?
A: Yes, with VStorage dynamic dispatch. Generic types require compile-time selection.
Q: Is the library thread-safe? A: Storage instances are not thread-safe by default. Use appropriate synchronization for concurrent access.
Q: How do I handle network failures with RemoteStorage?
A: The library returns StorageResult::Error for network issues. Implement retry logic in your application.
Built with โค๏ธ for the Veda platform