pub struct Channel { /* private fields */ }Expand description
In-memory, asynchronous, many-to-many byte channel with explicit backpressure semantics.
Writers and readers operate on a shared ring buffer while maintaining their own monotonic cursors. Reserving slices (writers) or releasing read positions (readers) is the only way to advance those cursors, ensuring deterministic progress and preventing aliasing of the underlying buffer.
Implementations§
Source§impl Channel
impl Channel
Sourcepub fn with_parameters(size: usize, backpressure: Backpressure) -> Arc<Self>
pub fn with_parameters(size: usize, backpressure: Backpressure) -> Arc<Self>
Create a channel with the given parameters.
Sourcepub fn new_writer(self: &Arc<Channel>) -> Writer
pub fn new_writer(self: &Arc<Channel>) -> Writer
Create a new writer to push bytes to the channel.
§Concurrency
Writers can work somewhat concurrently, given enough buffer space. This works by allowing multiple writers to reserve and write contiguous buffer “slices”, provided that those slices do not overwrite any part of the buffer being consumed by a strong reader. Readers are not aware of slices and will read the buffer in the order that slices are written. If a writer hangs while writing a slice, no subsequent slices will be read.
Sourcepub fn new_strong_writer(self: &Arc<Channel>) -> StrongWriter
pub fn new_strong_writer(self: &Arc<Channel>) -> StrongWriter
Create a new strong writer.
Sourcepub fn new_weak_writer(self: &Arc<Channel>) -> WeakWriter
pub fn new_weak_writer(self: &Arc<Channel>) -> WeakWriter
Create a new weak writer that acquires tail slots on demand.
Sourcepub fn new_strong_reader(self: &Arc<Channel>) -> StrongReader
pub fn new_strong_reader(self: &Arc<Channel>) -> StrongReader
Create a new reader that applies backpressure to writers if they are trying to overwrite the reader’s log position.
Note that the entire channel will be as slow as the slowest strong reader.
Sourcepub fn new_weak_reader(self: &Arc<Channel>) -> WeakReader
pub fn new_weak_reader(self: &Arc<Channel>) -> WeakReader
Create a new reader that can be overtaken by writers if the reader is too slow.
If you require a reader that cannot lose any data, create a StrongReader instead.
Sourcepub fn reserve_slice(&self, len: u64) -> u64
pub fn reserve_slice(&self, len: u64) -> u64
Reserve a tail position of given length to write to.
§Caution!
Failing to write the entire slice will result in permanent backpressure.
Sourcepub fn terminate(&self) -> Result<(), ChannelError>
pub fn terminate(&self) -> Result<(), ChannelError>
Safely terminate this channel.
This will cause any readers or writers to return io::ErrorKind::ConnectionAborted.
Sourcepub fn drain(&self) -> Result<(), ChannelError>
pub fn drain(&self) -> Result<(), ChannelError>
Start draining the channel.
When draining, a channel doesn’t accept any new frames from Writers, and rejects reads
once they catch up to the buffer tail.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Channel
impl !RefUnwindSafe for Channel
impl Send for Channel
impl Sync for Channel
impl Unpin for Channel
impl UnsafeUnpin for Channel
impl !UnwindSafe for Channel
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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 moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.