pub struct ModuloShardChooser { /* private fields */ }Expand description
A simple modulo-based shard chooser for numeric shard keys.
Routes based on shard_key % shard_count, producing shard names like
shard_0, shard_1, etc.
This is suitable for evenly distributed numeric keys (e.g., auto-increment IDs). Not suitable for sequential inserts (hotspotting on latest shard) or non-numeric keys.
Implementations§
Source§impl ModuloShardChooser
impl ModuloShardChooser
Sourcepub fn new(shard_count: usize) -> Self
pub fn new(shard_count: usize) -> Self
Create a new modulo shard chooser with the given number of shards.
Shards are named shard_0, shard_1, …, shard_{n-1}.
§Panics
Panics if shard_count is 0, as this would cause division by zero
when routing to shards.
Sourcepub fn with_prefix(self, prefix: impl Into<String>) -> Self
pub fn with_prefix(self, prefix: impl Into<String>) -> Self
Set a custom prefix for shard names (default: “shard_”).
Sourcepub fn shard_count(&self) -> usize
pub fn shard_count(&self) -> usize
Get the shard count.
Trait Implementations§
Source§impl Clone for ModuloShardChooser
impl Clone for ModuloShardChooser
Source§fn clone(&self) -> ModuloShardChooser
fn clone(&self) -> ModuloShardChooser
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ModuloShardChooser
impl Debug for ModuloShardChooser
Source§impl ShardChooser for ModuloShardChooser
impl ShardChooser for ModuloShardChooser
Source§fn choose_for_model(&self, shard_key: &Value) -> String
fn choose_for_model(&self, shard_key: &Value) -> String
Choose the shard for a model based on its shard key value. Read more
Source§fn choose_for_query(&self, hints: &QueryHints) -> Vec<String>
fn choose_for_query(&self, hints: &QueryHints) -> Vec<String>
Choose which shards to query based on query hints. Read more
Auto Trait Implementations§
impl Freeze for ModuloShardChooser
impl RefUnwindSafe for ModuloShardChooser
impl Send for ModuloShardChooser
impl Sync for ModuloShardChooser
impl Unpin for ModuloShardChooser
impl UnsafeUnpin for ModuloShardChooser
impl UnwindSafe for ModuloShardChooser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).