Skip to main content

StreamHandle

Trait StreamHandle 

Source
pub trait StreamHandle: Send {
    // Required methods
    fn next_payload<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<Option<StreamPayload>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn cancel<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn stream_id(&self) -> &str;
    fn is_completed(&self) -> bool;
}
Expand description

Object-safe stream handle for dynamic dispatch.

Generated portable clients use Box<dyn StreamHandle> so they work with any StreamHandleImpl<T> regardless of concrete transport.

§Send futures on native (#670)

On native the trait methods return Send futures (plain #[async_trait]), so a native Send + Sync Mount (e.g. the /stream pipe reader in hyprstream-rpc-std) can hold a StreamHandle future across .await. This is sound because the only implementors are StreamHandleImpl<T> and Box<dyn StreamHandle>, and StreamHandleImpl<T> is built entirely from the Transport associated types — which are already Send (Transport::Sub: Send, Transport::Pub: Send), and whose native PublishSink impls return Send futures.

On wasm the trait stays #[async_trait(?Send)]: the WebTransport WtPublisher::send_frames future holds JS values and is genuinely !Send, and the browser namespace never needs Send (wasm32 is single-threaded). The dual cfg_attr mirrors the hyprstream_vfs::Mount trait itself.

Required Methods§

Source

fn next_payload<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<Option<StreamPayload>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get next verified payload. Returns None on stream end.

Source

fn cancel<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Cancel the stream via ctrl channel.

Takes &mut self (not &self) so the returned future is Send without requiring Self: Sync — a dyn StreamHandle is Send but not Sync (its transport Sub/Pub are only Send-bound), so a &self future could not be sent across threads. &mut self also matches the state it mutates (the cancelled flag). See #670.

Source

fn stream_id(&self) -> &str

Get the stream ID.

Source

fn is_completed(&self) -> bool

Check if stream is completed.

Trait Implementations§

Source§

impl StreamHandle for Box<dyn StreamHandle>

Blanket impl for Box so callers can use it directly.

Source§

fn next_payload<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<Option<StreamPayload>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get next verified payload. Returns None on stream end.
Source§

fn cancel<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Cancel the stream via ctrl channel. Read more
Source§

fn stream_id(&self) -> &str

Get the stream ID.
Source§

fn is_completed(&self) -> bool

Check if stream is completed.

Implementations on Foreign Types§

Source§

impl StreamHandle for Box<dyn StreamHandle>

Blanket impl for Box so callers can use it directly.

Source§

fn next_payload<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<Option<StreamPayload>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn cancel<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn stream_id(&self) -> &str

Source§

fn is_completed(&self) -> bool

Implementors§

Source§

impl<T: Transport> StreamHandle for StreamHandleImpl<T>

Blanket impl: any StreamHandleImpl<T> satisfies StreamHandle.