Skip to main content

ChannelHandle

Trait ChannelHandle 

Source
pub trait ChannelHandle:
    Debug
    + Send
    + Sync {
    type Subscription<M>: Stream<Item = Result<M, SdkError>>
       where M: DeserializeOwned;
    type ReplyFuture<'a, Resp>: Future<Output = Result<Resp, SdkError>> + 'a
       where Self: 'a,
             Resp: DeserializeOwned + 'a;

    // Required methods
    fn publish<M>(&self, message: M) -> Result<PressureResponse, SdkError>
       where M: Serialize + SchemaValidate;
    fn subscribe<M>(&self) -> Self::Subscription<M>
       where M: DeserializeOwned;
    fn request_reply<Req, Resp>(
        &self,
        request: Req,
    ) -> Self::ReplyFuture<'_, Resp>
       where Req: Serialize + SchemaValidate,
             Resp: DeserializeOwned;
}
Expand description

Application-facing typed channel API.

ChannelHandle intentionally exposes typed messages only. It does not expose envelopes, byte buffers, protocol frames, publisher identifiers, or transport handles; embedded and remote implementations perform any necessary serialization and schema validation behind this trait.

§Object safety

This trait is not object-safe because its methods are generic over message types and because subscriptions/replies are represented with generic associated return types. Use concrete handle types behind generic bounds such as H: ChannelHandle, or define an application enum over the concrete handle implementations that need to be selected at runtime. Future SDK layers may add an explicitly erased adapter without weakening the typed API here.

use liminal_sdk::ChannelHandle;
use serde::Serialize;

#[derive(Serialize)]
struct OnlySerializable {
    id: String,
}

fn publish_without_schema<H>(handle: &H, message: OnlySerializable)
where
    H: ChannelHandle,
{
    let _ = handle.publish(message);
}

Required Associated Types§

Source

type Subscription<M>: Stream<Item = Result<M, SdkError>> where M: DeserializeOwned

Stream returned by subscribe for message type M.

Source

type ReplyFuture<'a, Resp>: Future<Output = Result<Resp, SdkError>> + 'a where Self: 'a, Resp: DeserializeOwned + 'a

Future returned by request_reply for reply type Resp.

Required Methods§

Source

fn publish<M>(&self, message: M) -> Result<PressureResponse, SdkError>

Publishes a typed message to the channel.

The message type must be serializable and must declare schema metadata; a merely serializable value is rejected at compile time. The returned PressureResponse reports whether the bus accepted, deferred, or rejected the publish attempt.

§Errors

Returns SdkError when the concrete channel implementation cannot serialize, validate, or submit the message for delivery.

Source

fn subscribe<M>(&self) -> Self::Subscription<M>

Subscribes to typed channel messages.

Subscription and delivery failures are surfaced to the application as SdkError items in the returned stream.

Source

fn request_reply<Req, Resp>(&self, request: Req) -> Self::ReplyFuture<'_, Resp>

Sends a typed request and resolves with a typed reply.

The request type must be serializable and schema-declared. The reply type must be owned after deserialization so callers never borrow transport buffers managed by an SDK implementation.

§Errors

The returned future resolves to SdkError when the concrete channel implementation cannot send the request, observe the reply, or deserialize the reply payload.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§