pub struct ChannelRegistry { /* private fields */ }Expand description
Registry of active streams for a connection.
Handles incoming streams (Data from wire → Rx<T> / Tx<T> handles).
For outgoing streams (server Tx<T> args), spawned tasks drain receivers
and send Data/Close messages via driver_tx.
r[impl channeling.unknown] - Unknown stream IDs cause Goodbye.
Implementations§
Source§impl ChannelRegistry
impl ChannelRegistry
Sourcepub fn new_with_credit_and_role(
conn_id: ConnectionId,
initial_credit: u32,
driver_tx: Sender<DriverMessage>,
role: Role,
) -> Self
pub fn new_with_credit_and_role( conn_id: ConnectionId, initial_credit: u32, driver_tx: Sender<DriverMessage>, role: Role, ) -> Self
Create a new registry with the given conn_id, initial credit, driver channel, and role.
The driver_tx is used to send all messages (Call/Data/Close/Response)
to the driver for transmission on the wire.
The role determines channel ID parity for response channels:
- Acceptor (server) uses even IDs
- Initiator (client) uses odd IDs
r[impl flow.channel.initial-credit] - Each stream starts with this credit.
Sourcepub fn new_with_credit(
initial_credit: u32,
driver_tx: Sender<DriverMessage>,
) -> Self
pub fn new_with_credit( initial_credit: u32, driver_tx: Sender<DriverMessage>, ) -> Self
Create a new registry with the given initial credit and driver channel. Uses ROOT conn_id and Acceptor role for backward compatibility (server-side usage).
r[impl flow.channel.initial-credit] - Each stream starts with this credit.
Sourcepub fn new(driver_tx: Sender<DriverMessage>) -> Self
pub fn new(driver_tx: Sender<DriverMessage>) -> Self
Create a new registry with default infinite credit.
r[impl flow.channel.infinite-credit] - Implementations MAY use very large credit. r[impl flow.channel.zero-credit] - With infinite credit, zero-credit never occurs. This disables backpressure but simplifies implementation.
Sourcepub fn conn_id(&self) -> ConnectionId
pub fn conn_id(&self) -> ConnectionId
Get the connection ID for this registry.
Sourcepub fn driver_tx(&self) -> Sender<DriverMessage>
pub fn driver_tx(&self) -> Sender<DriverMessage>
Get a clone of the driver message sender.
Used by codegen to spawn tasks that send Data/Close/Response messages.
Sourcepub fn response_channel_ids(&self) -> Arc<ChannelIdAllocator>
pub fn response_channel_ids(&self) -> Arc<ChannelIdAllocator>
Get the response channel ID allocator. Used by ForwardingDispatcher to allocate downstream channel IDs for response channels.
Sourcepub fn register_incoming(&mut self, channel_id: ChannelId, tx: Sender<Vec<u8>>)
pub fn register_incoming(&mut self, channel_id: ChannelId, tx: Sender<Vec<u8>>)
Register an incoming stream.
The connection layer will route Data messages for this channel_id to the sender.
Used for both Rx<T> (caller receives from callee) and Tx<T> (callee sends to caller).
r[impl flow.channel.initial-credit] - Stream starts with initial credit.
Sourcepub fn register_outgoing_credit(&mut self, channel_id: ChannelId)
pub fn register_outgoing_credit(&mut self, channel_id: ChannelId)
Register credit tracking for an outgoing stream.
The actual receiver is NOT stored here - the driver owns it directly. This only sets up credit tracking for the stream.
r[impl flow.channel.initial-credit] - Stream starts with initial credit.
Sourcepub fn prepare_route_data(
&mut self,
channel_id: ChannelId,
payload: Vec<u8>,
) -> Result<(Sender<Vec<u8>>, Vec<u8>), ChannelError>
pub fn prepare_route_data( &mut self, channel_id: ChannelId, payload: Vec<u8>, ) -> Result<(Sender<Vec<u8>>, Vec<u8>), ChannelError>
Route a Data message payload to the appropriate incoming stream.
Returns Ok(()) if routed successfully, Err(ChannelError) otherwise.
r[impl channeling.data] - Data messages routed by channel_id. r[impl channeling.data-after-close] - Reject data on closed streams. r[impl flow.channel.credit-overrun] - Reject if data exceeds remaining credit. r[impl flow.channel.credit-consume] - Deduct bytes from remaining credit. r[impl flow.channel.byte-accounting] - Credit measured in payload bytes.
Returns a sender and payload if routing is allowed, or an error. The actual send must be done by the caller to avoid holding locks across await.
Sourcepub async fn route_data(
&mut self,
channel_id: ChannelId,
payload: Vec<u8>,
) -> Result<(), ChannelError>
pub async fn route_data( &mut self, channel_id: ChannelId, payload: Vec<u8>, ) -> Result<(), ChannelError>
Route a Data message payload to the appropriate incoming stream.
Returns Ok(()) if routed successfully, Err(ChannelError) otherwise.
r[impl channeling.data] - Data messages routed by channel_id. r[impl channeling.data-after-close] - Reject data on closed streams. r[impl flow.channel.credit-overrun] - Reject if data exceeds remaining credit. r[impl flow.channel.credit-consume] - Deduct bytes from remaining credit. r[impl flow.channel.byte-accounting] - Credit measured in payload bytes.
Sourcepub fn close(&mut self, channel_id: ChannelId)
pub fn close(&mut self, channel_id: ChannelId)
Close an incoming stream (remove from registry).
Dropping the sender will cause the Rx<T>’s recv() to return None.
r[impl channeling.close] - Close terminates the stream. r[impl flow.channel.close-exempt] - Close doesn’t consume credit.
Sourcepub fn reset(&mut self, channel_id: ChannelId)
pub fn reset(&mut self, channel_id: ChannelId)
Reset a stream (remove from registry, discard credit).
r[impl channeling.reset] - Reset terminates the stream abruptly. r[impl channeling.reset.credit] - Outstanding credit is lost on reset.
Sourcepub fn receive_credit(&mut self, channel_id: ChannelId, bytes: u32)
pub fn receive_credit(&mut self, channel_id: ChannelId, bytes: u32)
Receive a Credit message - add credit for an outgoing stream.
r[impl flow.channel.credit-grant] - Credit message adds to available credit. r[impl flow.channel.credit-additive] - Credit accumulates additively.
Sourcepub fn contains(&self, channel_id: ChannelId) -> bool
pub fn contains(&self, channel_id: ChannelId) -> bool
Check if a stream ID is registered (either incoming or outgoing credit).
Sourcepub fn contains_incoming(&self, channel_id: ChannelId) -> bool
pub fn contains_incoming(&self, channel_id: ChannelId) -> bool
Check if a stream ID is registered as incoming.
Sourcepub fn contains_outgoing(&self, channel_id: ChannelId) -> bool
pub fn contains_outgoing(&self, channel_id: ChannelId) -> bool
Check if a stream ID has outgoing credit registered.
Sourcepub fn outgoing_count(&self) -> usize
pub fn outgoing_count(&self) -> usize
Get the number of active outgoing streams (by credit tracking).
Sourcepub fn outgoing_credit(&self, channel_id: ChannelId) -> Option<u32>
pub fn outgoing_credit(&self, channel_id: ChannelId) -> Option<u32>
Get remaining credit for an outgoing stream.
Returns None if stream is not registered.
Sourcepub fn incoming_credit(&self, channel_id: ChannelId) -> Option<u32>
pub fn incoming_credit(&self, channel_id: ChannelId) -> Option<u32>
Get remaining credit we’ve granted for an incoming stream.
Returns None if stream is not registered.
Sourcepub fn bind_streams<T: Facet<'static>>(&mut self, args: &mut T)
pub fn bind_streams<T: Facet<'static>>(&mut self, args: &mut T)
Bind streams in deserialized args for server-side dispatch.
Walks the args using Poke reflection to find any Rx<T> or Tx<T> fields.
For each stream found:
- For
Rx<T>: creates a channel, sets the receiver slot, registers for incoming data - For
Tx<T>: sets the task_tx so send() writes directly to the wire
§Example
let mut args = facet_postcard::from_slice::<(Rx<i32>, Tx<String>)>(&payload)?;
registry.bind_streams(&mut args);
let (input, output) = args;
// ... call handler with input, output ...
// When handler returns and Tx is dropped, Close is sent automaticallyAuto Trait Implementations§
impl Freeze for ChannelRegistry
impl RefUnwindSafe for ChannelRegistry
impl Send for ChannelRegistry
impl Sync for ChannelRegistry
impl Unpin for ChannelRegistry
impl UnwindSafe for ChannelRegistry
Blanket Implementations§
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<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more