Skip to main content

HandleProtocol

Trait HandleProtocol 

Source
pub trait HandleProtocol:
    Send
    + Sync
    + 'static {
    type Handle: Send + Sync + 'static;

    // Required methods
    fn open(&self, cx: HandleCx, request: Value) -> Result<Self::Handle, Error>;
    fn read(
        &self,
        handle: Arc<Self::Handle>,
        sub: Path,
    ) -> DetachedFuture<Option<Record>>;
    fn write(
        &self,
        handle: Arc<Self::Handle>,
        sub: Path,
        data: Record,
    ) -> DetachedFuture<Path>;

    // Provided methods
    fn close(&self, handle: Arc<Self::Handle>) { ... }
    fn docs(&self) -> Option<Value> { ... }
}
Expand description

The store-specific half of a handle store.

Implementations define per-handle state and the meaning of sub-paths under outstanding/{id}. All routing and lifecycle is handled by HandleStore.

Required Associated Types§

Source

type Handle: Send + Sync + 'static

Per-handle state. Stored behind an Arc so detached futures can hold it without borrowing the store.

Required Methods§

Source

fn open(&self, cx: HandleCx, request: Value) -> Result<Self::Handle, Error>

Open a handle for a request written to the store root.

Spawn any background work here; keep cx.cancel if parked reads need to fail on release.

Source

fn read( &self, handle: Arc<Self::Handle>, sub: Path, ) -> DetachedFuture<Option<Record>>

Serve a read below the handle. sub is relative to the handle (empty for a read of outstanding/{id} itself).

Source

fn write( &self, handle: Arc<Self::Handle>, sub: Path, data: Record, ) -> DetachedFuture<Path>

Serve a write below the handle. The returned path is relative to the handle; HandleStore prefixes outstanding/{id} so callers always see paths in their own namespace.

Provided Methods§

Source

fn close(&self, handle: Arc<Self::Handle>)

Called once when the handle is released (after cancellation).

Source

fn docs(&self) -> Option<Value>

Optional documentation served at docs.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§