Skip to main content

FrameSource

Trait FrameSource 

Source
pub trait FrameSource {
    // Required method
    fn next_frame(
        &self,
    ) -> impl Future<Output = Result<Option<String>, SourceError>> + Send;
}
Expand description

An inbound frame stream from a peer.

A stream of whole frames, protocol-neutral: nothing here names a method, a revision, or a message kind, because routing a frame to a method is the next layer’s job and the next layer is the one that knows the protocol.

Implemented by a transport. Consumed by the loop that routes. One method, for the same reason FrameSink has one.

§Examples

use protocol_droid::application::jsonrpc::{FrameSource, SourceError};

/// A source with nothing behind it, which reports a closed stream at once.
struct Closed;

impl FrameSource for Closed {
    async fn next_frame(&self) -> Result<Option<String>, SourceError> {
        Ok(None)
    }
}

Required Methods§

Source

fn next_frame( &self, ) -> impl Future<Output = Result<Option<String>, SourceError>> + Send

Waits for the peer’s next frame.

§Errors

SourceError when the frame could not be read, or when the bytes that arrived were not a frame. An implementor that has already failed may return the error for every later call; a caller does not assume a failure is permanent.

No + '_ on the return: edition 2024 already captures every in-scope lifetime in an RPIT, so spelling one out is not merely redundant — it is a bound the implementor would fail to satisfy.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<R> FrameSource for StdioSource<R>
where R: AsyncRead + Unpin + Send,