Silk

silk/buffered_duplex

Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc.

One scoped buffered session over an exclusive concrete ByteDuplex provider.

Details

withBuffered owns separate fixed input and output state for the callback and terminally closes the provider after success, typed failure, or structured cancellation/interruption. Fatal traps bypass finalizers and Drop. Release intentionally performs no implicit flush. close permits an earlier terminal close and abandons all buffered bytes without a flush.

Import as BufferedDuplex with import silk.buffered_duplex { BufferedDuplex }.

Public declarations: 7.

DEFAULT_CAPACITY

pub const DEFAULT_CAPACITY: usize

The default fixed capacity for each duplex direction.

BufferedDuplex

pub struct BufferedDuplex<'transport, P>

One callback-scoped buffered session owning direction states and borrowing a private provider.

Method BufferedDuplex.peek

pub fn peek<'transport, P, 'a>(self: &'a BufferedDuplex<'transport, P>) -> &'a [u8]

Borrows the initialized unread prefix, or an empty slice after terminal close.

Method BufferedDuplex.unread

pub fn unread<'transport, P, 'life2>(self: &'life2 BufferedDuplex<'transport, P>) -> usize

Returns the unread input count, or zero after terminal close.

Method BufferedDuplex.pending

pub fn pending<'transport, P, 'life2>(self: &'life2 BufferedDuplex<'transport, P>) -> usize

Returns the pending output count, or zero after terminal close.

Method BufferedDuplex.consume

pub effect<'env> fn consume<'transport: 'env, P: 'env, 'life2: 'env, 'env>(self: &'life2 mut BufferedDuplex<'transport, P>, count: usize) -> () ! BufferError

Consumes exactly an initialized unread prefix.

Method BufferedDuplex.fill

pub effect<'env> fn fill<'transport: 'env, P: 'env, 'life2: 'env, 'env>(self: &'life2 mut BufferedDuplex<'transport, P>, minimum: usize, deadline: silk/option.Option<silk/system_clock.Instant>) -> FillOutcome ! BufferError ? &mut MonotonicClock where &mut P provides &ByteDuplex from &mut ByteDuplex | &mut MonotonicClock

Retains at least minimum input bytes or reports sticky source end.

Method BufferedDuplex.readSome

pub effect<'env> fn readSome<'transport: 'env, P: 'env, 'life2: 'env, 'life3: 'env, 'env>(self: &'life2 mut BufferedDuplex<'transport, P>, output: &'life3 mut [u8], deadline: silk/option.Option<silk/system_clock.Instant>) -> ReadTransfer ! BufferError ? &mut MonotonicClock where &mut P provides &ByteDuplex from &mut ByteDuplex | &mut MonotonicClock

Copies one retained or newly read prefix.

Method BufferedDuplex.readExact

pub effect<'env> fn readExact<'transport: 'env, P: 'env, 'life2: 'env, 'life3: 'env, 'env>(self: &'life2 mut BufferedDuplex<'transport, P>, output: &'life3 mut [u8], deadline: silk/option.Option<silk/system_clock.Instant>) -> () ! BufferError ? &mut MonotonicClock where &mut P provides &ByteDuplex from &mut ByteDuplex | &mut MonotonicClock

Fills the complete destination or reports its exact copied prefix.

Method BufferedDuplex.discardAtMost

pub effect<'env> fn discardAtMost<'transport: 'env, P: 'env, 'life2: 'env, 'env>(self: &'life2 mut BufferedDuplex<'transport, P>, limit: usize, deadline: silk/option.Option<silk/system_clock.Instant>) -> DiscardOutcome ! BufferError ? &mut MonotonicClock where &mut P provides &ByteDuplex from &mut ByteDuplex | &mut MonotonicClock

Discards no more than one finite limit.

Method BufferedDuplex.discardExact

pub effect<'env> fn discardExact<'transport: 'env, P: 'env, 'life2: 'env, 'env>(self: &'life2 mut BufferedDuplex<'transport, P>, count: usize, deadline: silk/option.Option<silk/system_clock.Instant>) -> () ! BufferError ? &mut MonotonicClock where &mut P provides &ByteDuplex from &mut ByteDuplex | &mut MonotonicClock

Discards exactly one finite count.

Method BufferedDuplex.writeSome

pub effect<'env> fn writeSome<'transport: 'env, P: 'env, 'life2: 'env, 'life3: 'env, 'env>(self: &'life2 mut BufferedDuplex<'transport, P>, input: &'life3 [u8], deadline: silk/option.Option<silk/system_clock.Instant>) -> usize ! BufferError ? &mut MonotonicClock where &mut P provides &ByteDuplex from &mut ByteDuplex | &mut MonotonicClock

Accepts one positive input prefix into owned pending storage.

Method BufferedDuplex.writeAll

pub effect<'env> fn writeAll<'transport: 'env, P: 'env, 'life2: 'env, 'life3: 'env, 'env>(self: &'life2 mut BufferedDuplex<'transport, P>, input: &'life3 [u8], deadline: silk/option.Option<silk/system_clock.Instant>) -> () ! BufferError ? &mut MonotonicClock where &mut P provides &ByteDuplex from &mut ByteDuplex | &mut MonotonicClock

Accepts one complete finite input in order.

Method BufferedDuplex.writeVecAll

pub effect<'env> fn writeVecAll<'transport: 'env, P: 'env, 'life2: 'env, 'life3: 'env, 'env>(self: &'life2 mut BufferedDuplex<'transport, P>, inputs: &'life3 [silk/bytes.Bytes], deadline: silk/option.Option<silk/system_clock.Instant>) -> () ! BufferError ? &mut MonotonicClock where &mut P provides &ByteDuplex from &mut ByteDuplex | &mut MonotonicClock

Accepts borrowed byte vectors in order after checking aggregate length arithmetic.

Method BufferedDuplex.flush

pub effect<'env> fn flush<'transport: 'env, P: 'env, 'life2: 'env, 'env>(self: &'life2 mut BufferedDuplex<'transport, P>, deadline: silk/option.Option<silk/system_clock.Instant>) -> () ! BufferError ? &mut MonotonicClock where &mut P provides &ByteDuplex from &mut ByteDuplex | &mut MonotonicClock

Writes pending bytes exactly once and then flushes the provider boundary.

Method BufferedDuplex.finish

pub effect<'env> fn finish<'transport: 'env, P: 'env, 'life2: 'env, 'env>(self: &'life2 mut BufferedDuplex<'transport, P>, deadline: silk/option.Option<silk/system_clock.Instant>) -> () ! BufferError ? &mut MonotonicClock where &mut P provides &ByteDuplex from &mut ByteDuplex | &mut MonotonicClock

Explicitly finishes pending output.

Method BufferedDuplex.shutdownWrite

pub effect<'env> fn shutdownWrite<'transport: 'env, P: 'env, 'life2: 'env, 'env>(self: &'life2 mut BufferedDuplex<'transport, P>, deadline: silk/option.Option<silk/system_clock.Instant>) -> () ! BufferError ? &mut MonotonicClock where &mut P provides &ByteDuplex from &mut ByteDuplex | &mut MonotonicClock

Flushes pending output and then closes only the provider's write direction.

Details

A successful shutdown keeps input available but rejects later output operations. Any typed transport failure terminalizes the complete session. Structured cancellation is handled by the enclosing buffered scope, which terminally closes the retained provider.

Method BufferedDuplex.close

pub effect<'env> fn close<'transport: 'env, P: 'env, 'life2: 'env, 'env>(self: &'life2 mut BufferedDuplex<'transport, P>) -> () ! ByteIoError where &mut P provides &ByteDuplex from &mut ByteDuplex

Terminally closes the provider once and abandons all buffered bytes without a flush.

Details

The operation marks the complete session terminal before it calls the provider. peek, unread, and pending report no buffered bytes after the call starts. Repeated calls succeed without another provider close, including after the first call returns ByteIoError.

BufferedContext

pub interface BufferedContext<P, A, E, ?R>

Compile-time adapter from one owned context to a higher-ranked buffered session use.

Details

Implement this interface when a scoped callback owns affine or once-callable state. The selected operation consumes that context and receives the temporary session independently; interface selection adds no runtime service or requirement-row member.

Operation use

effect<'session> fn use<'session: 'session, 'transport: 'session>(context: Self, session: &'session mut silk/buffered_duplex.BufferedDuplex<'transport, P>) -> A ! E ? R where &mut P provides &ByteDuplex from &mut ByteDuplex | &mut MonotonicClock

Consumes one owned context while using a temporary buffered session.

withBuffered

pub effect<'env1> fn withBuffered<'env: 'env1, A, E, ?CallbackRequirements, P: 'env1, 'env1>(transport: &'env mut P, callback: for<'call> once fn<'env>(&'call mut silk/buffered_duplex.BufferedDuplex<'call, P>) -> once Effect<'call & 'env; A ! E ? CallbackRequirements>) -> A ! E | BufferError | OutOfMemoryError ? CallbackRequirements | &mut Allocator where &mut P provides &ByteDuplex from &mut ByteDuplex, &mut P provides &ByteDuplex from &mut ByteDuplex | &mut MonotonicClock, CallbackRequirements in Without<CallbackRequirements, &ByteDuplex>

Runs one callback with default 8,192-byte input and output buffers.

withBufferedCapacity

pub effect<'env1> fn withBufferedCapacity<'env: 'env1, A, E, ?CallbackRequirements, P: 'env1, 'env1>(transport: &'env mut P, inputCapacity: usize, outputCapacity: usize, callback: for<'call> once fn<'env>(&'call mut silk/buffered_duplex.BufferedDuplex<'call, P>) -> once Effect<'call & 'env; A ! E ? CallbackRequirements>) -> A ! E | BufferError | OutOfMemoryError ? CallbackRequirements | &mut Allocator where &mut P provides &ByteDuplex from &mut ByteDuplex, &mut P provides &ByteDuplex from &mut ByteDuplex | &mut MonotonicClock, CallbackRequirements in Without<CallbackRequirements, &ByteDuplex>

Runs one callback with explicitly bounded direction capacities.

withBufferedCapacityContext

pub effect<'env1> fn withBufferedCapacityContext<'env: 'env1, A, E, ?CallbackRequirements, P: 'env1, C: 'env1, 'env1>(transport: &'env mut P, inputCapacity: usize, outputCapacity: usize, context: C) -> A ! E | BufferError | OutOfMemoryError ? CallbackRequirements | &mut Allocator where &mut P provides &ByteDuplex from &mut ByteDuplex, &mut P provides &ByteDuplex from &mut ByteDuplex | &mut MonotonicClock, CallbackRequirements in Without<CallbackRequirements, &ByteDuplex>

Runs one compile-time-selected context adapter with explicit direction capacities.

Details

The context is consumed by value and may own affine or once-callable state. The selected use operation on BufferedContext receives an independently higher-ranked temporary session, which cannot escape through the context or result.

withBufferedPairCapacity

pub effect<'env1> fn withBufferedPairCapacity<'env: 'env1, A, E, ?CallbackRequirements, SP: 'env1, DP: 'env1, 'env1>(source: &'env mut SP, sourceInputCapacity: usize, sourceOutputCapacity: usize, destination: &'env mut DP, destinationInputCapacity: usize, destinationOutputCapacity: usize, callback: for<'sourceCall, 'destinationCall> once fn<'env>(&'sourceCall mut silk/buffered_duplex.BufferedDuplex<'sourceCall, SP>, &'destinationCall mut silk/buffered_duplex.BufferedDuplex<'destinationCall, DP>) -> once Effect<'sourceCall & 'destinationCall; A ! E ? CallbackRequirements>) -> A ! E | BufferError | OutOfMemoryError ? CallbackRequirements | &mut Allocator where &mut SP provides &ByteDuplex from &mut ByteDuplex, &mut DP provides &ByteDuplex from &mut ByteDuplex, &mut SP provides &ByteDuplex from &mut ByteDuplex | &mut MonotonicClock, &mut DP provides &ByteDuplex from &mut ByteDuplex | &mut MonotonicClock, CallbackRequirements in Without<CallbackRequirements, &ByteDuplex>

Runs one callback with two explicitly bounded buffered sessions.

Details

All four capacities are validated before allocation or lease acquisition. Both transports are terminally closed exactly once after success, typed failure, or structured cancellation/interruption; fatal traps bypass finalizers and Drop. Neither pending output is implicitly flushed.

On this page