Skip to main content

Service

Trait Service 

Source
pub trait Service:
    Send
    + Sync
    + 'static {
    // Required methods
    fn subscribe(
        &self,
        ctx: RequestContext,
        request: OwnedSubscribeRequestView,
    ) -> impl Future<Output = ServiceResult<ServiceStream<impl Encodable<SubscribeResponse> + Send + use<Self>>>> + Send;
    fn query<'a>(
        &'a self,
        ctx: RequestContext,
        request: OwnedQueryRequestView,
    ) -> impl Future<Output = ServiceResult<impl Encodable<QueryResponse> + Send + use<'a, Self>>> + Send;
    fn tables<'a>(
        &'a self,
        ctx: RequestContext,
        request: OwnedTablesRequestView,
    ) -> impl Future<Output = ServiceResult<impl Encodable<TablesResponse> + Send + use<'a, Self>>> + Send;
}
Expand description

Streaming SQL predicate service over a server-side KvSchema. The server registers a fixed set of SQL tables at startup (schema lives on the server, not the wire). Each RPC names one of those tables.

§Implementing handlers

Handlers receive requests as OwnedFooView (an alias for OwnedView<FooView<'static>>), which gives zero-copy borrowed access to fields (e.g. request.name is a &str into the decoded buffer). The view can be held across .await points. When two RPC types in the same package would alias to the same Owned<…>View name (e.g. a local message plus an imported one with the same short name), the alias is suppressed for both and the request type is spelled as OwnedView<…View<'static>> directly in the trait signature.

Implement methods with plain async fn; the returned future satisfies the Send bound automatically. See the buffa user guide for zero-copy access patterns and when to_owned_message() is needed.

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 (unary methods use use<'a, Self> and may borrow), so stream items must be 'static. To stream view-encoded data, encode each item inside the stream body and yield PreEncoded — see its # Streaming example doc.

Required Methods§

Source

fn subscribe( &self, ctx: RequestContext, request: OwnedSubscribeRequestView, ) -> impl Future<Output = ServiceResult<ServiceStream<impl Encodable<SubscribeResponse> + Send + use<Self>>>> + Send

Re-run a SQL WHERE predicate against every incoming batch that touches table’s primary-key codec family. Emits one SubscribeResponse per matched batch containing just the rows that satisfied the predicate.

Source

fn query<'a>( &'a self, ctx: RequestContext, request: OwnedQueryRequestView, ) -> impl Future<Output = ServiceResult<impl Encodable<QueryResponse> + Send + use<'a, Self>>> + Send

Ad-hoc unary SQL against the server-side session. Useful for inspecting the current table state alongside the live subscription.

'a lets the response body borrow from &self (e.g. server-resident state).

Source

fn tables<'a>( &'a self, ctx: RequestContext, request: OwnedTablesRequestView, ) -> impl Future<Output = ServiceResult<impl Encodable<TablesResponse> + Send + use<'a, Self>>> + Send

Describe every registered table. Carries KV-specific metadata (primary-key order, secondary indexes with their layout + cover columns) that DataFusion’s information_schema doesn’t surface.

'a lets the response body borrow from &self (e.g. server-resident state).

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§