Skip to main content

StreamingHandler

Trait StreamingHandler 

Source
pub trait StreamingHandler<Req, Res>:
    Send
    + Sync
    + 'static
where Req: Message + Send + 'static, Res: Message + Send + 'static,
{ type Item: Encodable<Res> + Send + 'static; // Required method fn call( &self, ctx: RequestContext, request: Req, ) -> BoxFuture<'static, ServiceResult<ServiceStream<Self::Item>>>; }
Expand description

Trait for server streaming RPC handlers.

§Migrating from connectrpc 0.4.x

Item is new in 0.5: a hand-written impl StreamingHandler previously returned ServiceStream<Res>; add type Item = Res; to keep the same behavior. Generated traits and the streaming_handler_fn helper infer it.

Required Associated Types§

Source

type Item: Encodable<Res> + Send + 'static

The stream item type. Typically Res itself; may be PreEncoded or MaybeBorrowed for handlers that encode borrowing views per item.

Items must be 'static — a stream item cannot borrow &self or a per-call snapshot. To stream view-encoded data, encode each item inside the stream’s body and yield PreEncoded.

Required Methods§

Source

fn call( &self, ctx: RequestContext, request: Req, ) -> BoxFuture<'static, ServiceResult<ServiceStream<Self::Item>>>

Handle a server streaming RPC request.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl<F, Fut, Req, Res, B> StreamingHandler<Req, Res> for FnStreamingHandler<F>
where F: Fn(RequestContext, Req) -> Fut + Send + Sync + 'static, Fut: Future<Output = ServiceResult<ServiceStream<B>>> + Send + 'static, Req: Message + Send + 'static, Res: Message + Send + 'static, B: Encodable<Res> + Send + 'static,

Source§

type Item = B