pub trait ServerReflection:
Send
+ Sync
+ 'static {
// Required method
fn server_reflection_info(
&self,
ctx: RequestContext,
requests: ServiceStream<StreamMessage<ServerReflectionRequest>>,
) -> impl Future<Output = ServiceResult<ServiceStream<impl Encodable<ServerReflectionResponse> + Send + use<Self>>>> + Send;
}Expand description
Generated v1 service trait and registration extension, for callers that mount a single protocol version by hand:
use std::sync::Arc;
use connectrpc::Router;
use connectrpc_reflection::{Reflector, ReflectionService, ServerReflectionExt};
let reflector = Reflector::from_descriptor_set_bytes(descriptor_set_bytes()).unwrap();
let service = Arc::new(ReflectionService::new(reflector));
let router = service.register(Router::new()); // v1 onlyServer trait for ServerReflection.
§Implementing handlers
Implement methods with plain async fn; the returned future satisfies
the Send bound automatically.
Unary and server-streaming requests arrive as
ServiceRequest<'_, Req>: a zero-copy
view of the request plus its body, valid for the duration of the call.
Fields are read directly (request.name is a &str into the decoded
buffer) and the borrow may be held across .await points. Anything
that must outlive the call — tokio::spawn, channels, server state,
or data captured by a returned response stream — takes owned data:
call request.to_owned_message() (or copy the specific fields)
first.
Client-streaming and bidi requests arrive as
ServiceStream<StreamMessage<Req>>.
Each item owns its decoded buffer and is Send + 'static, so items
can be buffered or moved into spawned tasks; read fields zero-copy
through the generated accessor methods (item.name()) or .view(),
convert with .to_owned_message(), or yield an item back unchanged —
StreamMessage<M> implements Encodable<M>.
Request types resolved through extern_path (e.g. well-known types
from another crate) use the same wrappers; the crate that owns the
type must be generated with buffa ≥ 0.7.0 and views enabled so the
backing HasMessageView impl exists.
The impl Encodable<Out> return bound accepts the owned Out, the
generated OutView<'_> / OwnedOutView,
MaybeBorrowed, or
PreEncoded for handlers that encode a
non-'static view internally and pass the bytes across the handler
boundary. View bodies are not emitted for output types mapped via
extern_path (the impl would be an orphan); return owned for
WKT/extern outputs.
Server-streaming and bidi-streaming methods return
ServiceStream<impl Encodable<Out> + Send + use<Self>>. The
use<Self> precise-capturing clause excludes &self’s lifetime and
the request’s lifetime (unary methods use use<'a, Self> and may
borrow from &self), so stream items must be 'static and cannot
borrow from the request. To stream view-encoded data, encode each
item inside the stream body and yield
PreEncoded — see its # Streaming example doc.
Required Methods§
Sourcefn server_reflection_info(
&self,
ctx: RequestContext,
requests: ServiceStream<StreamMessage<ServerReflectionRequest>>,
) -> impl Future<Output = ServiceResult<ServiceStream<impl Encodable<ServerReflectionResponse> + Send + use<Self>>>> + Send
fn server_reflection_info( &self, ctx: RequestContext, requests: ServiceStream<StreamMessage<ServerReflectionRequest>>, ) -> impl Future<Output = ServiceResult<ServiceStream<impl Encodable<ServerReflectionResponse> + Send + use<Self>>>> + Send
The reflection service is structured as a bidirectional stream, ensuring all related requests go to a single server.
Each requests item is a StreamMessage:
it owns its buffer, is Send + 'static, and exposes zero-copy
accessor methods (item.name()), .view(), and
.to_owned_message().
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".