Expand description
§StaticId
This library provides an extremely memory-efficient implementation of StaticId
for handling interned identifiers with optimal performance.
§Features
StaticId
: A highly optimized, interned identifier type combining a code and a venue.- Exceptional memory efficiency: Each
StaticId
is represented by a single 64-bit pointer. - Ultra-fast comparisons: Equality checks and hashing operations only compare 8 bytes, regardless of the actual string length.
- Lazy evaluation: The actual string data is only accessed during serialization.
§Limitations
- The bound of
code
andvenue
are fixed: For StaticIdNxM, the maximum length ofcode
andvenue
is N and M respectively. The exceeding characters will be truncated. - The given structs are:
- StaticId16x0
- StaticId16x16
- StaticId16x32
- StaticId16x64
- StaticId32x0
- StaticId32x16
- StaticId32x32 (=StaticId)
- StaticId32x64
- StaticId64x0
- StaticId64x16
- StaticId64x32
- StaticId64x64
§Usage
use static_id::StaticId;
assert_eq!(size_of::<StaticId>(), 8);
let id = StaticId::from_str("AAPL", "NASDAQ");
assert_eq!(id.get_id().code.as_str(), "AAPL");
assert_eq!(id.get_id().venue.as_str(), "NASDAQ");
assert_eq!(id.code_str(), "AAPL");
assert_eq!(id.venue_str(), "NASDAQ");
// Fast equality check (compares only 8 bytes)
let id2 = StaticId::from_str("AAPL", "NASDAQ");
assert_eq!(id, id2);
println!("ID: {}", id); // => AAPL@NASDAQ