PartitionBy

Struct PartitionBy 

Source
pub struct PartitionBy<St, Fut, F, K>
where St: Stream, K: Clone,
{ /* private fields */ }
Expand description

A stream that partitions items from an underlying stream into multiple sub-streams based on keys generated by an async function.

This struct implements Stream and yields (K, Partitioned<St, K>) tuples, where each tuple represents a new partition with its associated key and the sub-stream for that partition.

Items from the underlying stream are processed through the key function f, and items with the same key are grouped together into the same partition stream.

Implementations§

Source§

impl<St, Fut, F, K> PartitionBy<St, Fut, F, K>
where St: Stream, St::Item: Clone, F: Fn(&St::Item) -> Fut, Fut: Future<Output = K>, K: Hash + Eq + Clone,

Shared state between the main partitioning stream and all partition sub-streams.

This structure coordinates the distribution of items from the source stream to the appropriate partition streams. It maintains queues of pending items for each key and tracks the overall state of the partitioning operation.

Source

pub fn get_partition(&mut self, key: K) -> Partitioned<St, Fut, F, K>

Gets a partition stream for a specific key.

Must not be called with the same key twice, otherwise items will be missed.

§Arguments
  • key - The key for which to get a partition stream
§Returns

A Partitioned stream that yields only items matching the specified key.

Source

pub fn register_keys<I>(&mut self, keys: I)
where I: IntoIterator<Item = K>,

Pre-creates queues for multiple keys.

§Arguments
  • keys - An iterator of keys to pre-register
Source

pub fn allows_new_partitions(&self) -> bool

Returns whether new partitions are allowed to be created.

Source

pub fn set_allow_new_queues(&mut self, allow: bool)

Sets whether new queues are allowed to be created.

If set to false, only keys that already have queues (either from previous calls to get_partition or register_keys) will receive items. Items for unknown keys will be dropped.

Trait Implementations§

Source§

impl<'__pin, St, Fut, F, K> Unpin for PartitionBy<St, Fut, F, K>
where PinnedFieldsOf<__Origin<'__pin, St, Fut, F, K>>: Unpin, St: Stream, K: Clone,

Auto Trait Implementations§

§

impl<St, Fut, F, K> Freeze for PartitionBy<St, Fut, F, K>
where St: Freeze, F: Freeze, Fut: Freeze, <St as Stream>::Item: Freeze,

§

impl<St, Fut, F, K> RefUnwindSafe for PartitionBy<St, Fut, F, K>

§

impl<St, Fut, F, K> Send for PartitionBy<St, Fut, F, K>
where St: Send, F: Send, Fut: Send, <St as Stream>::Item: Send, K: Send,

§

impl<St, Fut, F, K> Sync for PartitionBy<St, Fut, F, K>
where St: Sync + Send, F: Sync + Send, Fut: Sync + Send, <St as Stream>::Item: Sync + Send, K: Sync + Send,

§

impl<St, Fut, F, K> UnwindSafe for PartitionBy<St, Fut, F, K>
where St: UnwindSafe, F: UnwindSafe, Fut: UnwindSafe, <St as Stream>::Item: UnwindSafe, K: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.