-
Notifications
You must be signed in to change notification settings - Fork 196
Feat: Make Batch a customizable type in RaftTypeConfig #1657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,105 @@ | ||||||
| //! Trait definition for customizable batch containers in Raft. | ||||||
|
|
||||||
| use std::fmt::Debug; | ||||||
| use std::fmt::Display; | ||||||
|
|
||||||
| use super::display::DisplayBatch; | ||||||
| use crate::OptionalSend; | ||||||
|
|
||||||
| /// Trait for batch containers used throughout Raft for efficient element grouping. | ||||||
| /// | ||||||
| /// This trait abstracts over different batch container implementations while | ||||||
| /// preserving performance characteristics required by Raft. | ||||||
| /// | ||||||
| /// Implementations may optimize for: | ||||||
| /// - Avoiding heap allocation for small batches | ||||||
| /// - Arena or pool-backed allocation | ||||||
| /// - Cache locality | ||||||
| /// | ||||||
| /// # Design Notes | ||||||
| /// | ||||||
| /// - The trait is `Sized` to enable static dispatch and full monomorphization. | ||||||
| /// - Iteration is explicit via `iter()` / `iter_mut()` to preserve lifetime and `ExactSizeIterator` | ||||||
| /// guarantees. | ||||||
| /// - Consuming iteration via `into_iter()` method with explicit `IntoIter` associated type. | ||||||
| pub trait RaftBatch<T>: OptionalSend + Sized + Default + Debug + 'static | ||||||
| where T: OptionalSend + Debug + 'static | ||||||
|
||||||
| where T: OptionalSend + Debug + 'static | |
| where T: OptionalSend + 'static |
Copilot
AI
Feb 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RaftBatch defines a custom into_iter(self) method while many batch implementations (including the default Batch<T>) also implement IntoIterator. This creates an API footgun (and can lead to method-call ambiguity in non-generic code when both traits are in scope). Consider making RaftBatch extend IntoIterator<Item = T, IntoIter = Self::IntoIter> and removing/renaming this method to avoid conflicts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unsafe impl Send for BatchIter<T>appears unnecessary becauseBatchIter<T>is composed ofOption<T>andvec::IntoIter<T>, which are alreadySendwhenT: Send, so the enum should auto-implementSend. Keeping an explicitunsafe implis risky because it can silently become unsound ifBatchIterinternals change; prefer relying on auto traits (or, if needed, add safe bounds via wrapper types rather thanunsafe).