vecdb_derive
Procedural macros for vecdb that enable custom types to work with compressed storage.
What is vecdb_derive?
This crate provides derive macros that automatically implement compression traits for custom wrapper types, allowing them to be used seamlessly with vecdb's compressed storage variants.
Features
- Automatic trait implementation: Generates
StoredCompressed
for wrapper types - Zero-cost abstractions: Wrappers have the same compression characteristics as inner types
- Generic support: Works with generic types and proper trait bounds
- Type safety: Compile-time guarantees for compression compatibility
Derive Macros
#[derive(StoredCompressed)]
Automatically implements compression traits for single-field tuple structs.
Requirements:
- Must be a tuple struct with exactly one field
- The inner type must implement
StoredCompressed
Usage
Basic Wrapper Types
use StoredCompressed;
use ;
// Type-safe wrappers around numeric types
;
;
Generic Wrapper Types
use StoredCompressed;
// Generic wrapper preserves compression characteristics
;
// Can be used with any StoredCompressed type
type Temperature = ;
type Count = ;
Real-World Example
use StoredCompressed;
use ;
;
;
Generated Code
For a simple wrapper:
;
The macro generates:
For generic types:
;
The macro generates:
Error Messages
Clear error messages for common mistakes:
- Wrong structure: "StoredCompressed can only be derived for single-field tuple structs"
- Only tuple structs with exactly one field are supported
Limitations
- Only works with single-field tuple structs
- Inner type must implement
StoredCompressed
- Does not work with enums, regular structs, or unit structs
Benefits
- Type Safety: Prevent mixing incompatible data types
- Zero Cost: No runtime overhead compared to raw types
- Compression: Maintains all compression benefits of the inner type
- Integration: Works seamlessly with all vecdb storage variants
When to Use
Use #[derive(StoredCompressed)]
to:
- Create domain-specific wrapper types
- Add type safety to numeric identifiers
- Build APIs that prevent value confusion
- Maintain compression efficiency with custom types
Compatibility
Derived types work with all vecdb storage variants:
CompressedVec<I, T>
: Compressed storageRawVec<I, T>
: Uncompressed storageComputedVec
: Derived data storage
This README was generated by Claude Code