pub struct Sink<T: Record> { /* private fields */ }Expand description
A streaming data sink.
Sinks receive records from a Source and distribute them to subscribers. The sink supports both single-subscriber and broadcast modes.
§Subscription Model
When you call subscribe(), you get a Subscription that receives
records from this sink. If you subscribe multiple times, the sink
automatically enters broadcast mode where each subscriber gets a
copy of every record.
§Performance Notes
- Single subscriber mode: Zero overhead, direct channel access
- Broadcast mode: Uses
RwLockfor subscriber list (read-heavy optimization) poll_and_distribute(): Takes a read lock (fast, non-blocking with other readers)subscribe(): Takes a write lock (rare, happens at setup time)
§Example
let (source, sink) = streaming::create::<MyEvent>(1024);
// Subscribe to receive records
let subscription = sink.subscribe();
// Process records
while let Some(batch) = subscription.poll() {
process(batch);
}Implementations§
Source§impl<T: Record> Sink<T>
impl<T: Record> Sink<T>
Sourcepub fn subscribe(&self) -> Subscription<T> ⓘ
pub fn subscribe(&self) -> Subscription<T> ⓘ
Creates a subscription to receive records from this sink.
The first subscriber receives records directly from the source channel. Additional subscribers trigger broadcast mode where records are copied.
§Returns
A Subscription that can be used to poll or receive records.
§Performance
This method takes a write lock and should only be called during setup, not on the hot path. Subscription setup is O(1).
§Panics
Panics if the internal lock is poisoned (should not happen in normal use).
Sourcepub fn subscriber_count(&self) -> usize
pub fn subscriber_count(&self) -> usize
Returns the number of active subscribers.
Sourcepub fn is_disconnected(&self) -> bool
pub fn is_disconnected(&self) -> bool
Returns true if the source has been dropped.
Sourcepub fn poll_and_distribute(&self) -> usizewhere
T: Clone,
pub fn poll_and_distribute(&self) -> usizewhere
T: Clone,
Polls for records and distributes them to subscribers.
In single-subscriber mode, this is a no-op (direct channel). In broadcast mode, this copies records to all subscriber channels.
Returns the number of records distributed.
§Performance
Snapshots subscriber producers under the read lock (cheap Arc bumps), then releases the lock before the poll loop to avoid holding it during I/O.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Sink<T>
impl<T> !RefUnwindSafe for Sink<T>
impl<T> Send for Sink<T>
impl<T> Sync for Sink<T>
impl<T> Unpin for Sink<T>
impl<T> UnsafeUnpin for Sink<T>
impl<T> !UnwindSafe for Sink<T>
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more