Skip to main content
pub trait ShardKeyExtractor 
    // Required method
    fn shard_key_values(&self) -> ShardKeyValues<’_>;

Trait for extracting shard key values from a record.

Records must implement this trait to enable shard-aware routing. Returns a SmallVec of (column_name, typed_value) pairs for shard key columns.

Performance

  • Returns ShardKeyValues (SmallVec) which is stack-allocated for up to 4 columns
  • Use typed variants (Int, Long, Float, Double) when possible to avoid string parsing overhead
  • The String variants are for string/char columns, and specialized variants (Date, Ipv4, Decimal) handle formatted types
  • Use the smallvec! macro for convenient construction

Example

Required Methods

Returns shard key column names and their typed values.

Only columns that are part of the shard key need to be included. Returns a SmallVec which is stack-allocated for up to 4 shard columns.

Dyn Compatibility

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called “object safety”.

Implementations on Foreign Types

Source

impl ShardKeyExtractor for String

A JSON record, as a BulkInserter in JSON mode takes it. Its key is not read: it has no shard key values, and each record goes to the rank of a random shard.

Implementors