pub trait RawSortKey:
Ord
+ Clone
+ Send
+ Sync
+ Sized {
const SERIALIZED_SIZE: Option<usize>;
// Required methods
fn extract(bam: &[u8], ctx: &SortContext) -> Self;
fn write_to<W: Write>(&self, writer: &mut W) -> Result<()>;
fn read_from<R: Read>(reader: &mut R) -> Result<Self>;
}Expand description
Trait for sort keys extracted from raw BAM bytes.
This trait provides a unified interface for all sort key types, enabling:
- Zero-copy key extraction from raw BAM bytes
- Efficient serialization for temp file storage
- O(1) comparisons during merge phase (for fixed-size keys)
§Design
Inspired by fgbio’s SamOrder trait and samtools’ bam1_tag approach.
Using a trait with monomorphization (sort_with_keyed<K>) gives:
- Zero-cost abstraction (no runtime dispatch)
- Type safety (can’t mix key types)
- Compile-time optimization (inlining, etc.)
Required Associated Constants§
Sourceconst SERIALIZED_SIZE: Option<usize>
const SERIALIZED_SIZE: Option<usize>
Fixed byte size when serialized, or None for variable-length keys.
Fixed-size keys enable O(1) reads from temp files during merge.
Required Methods§
Sourcefn extract(bam: &[u8], ctx: &SortContext) -> Self
fn extract(bam: &[u8], ctx: &SortContext) -> Self
Extract a sort key from raw BAM record bytes.
This is the hot path during sorting - implementations should minimize parsing overhead by reading only the fields needed for comparison.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.