Skip to main content

Transport

Trait Transport 

Source
pub trait Transport {
    // Required methods
    fn call(&self, name: String, params: Value) -> Result<Value, Error>;
    fn cast(&self, name: String, params: Value);
    fn context(&self) -> Option<String>;

    // Provided method
    fn call_bytes(
        &self,
        name: String,
        params: Value,
        into: &mut Vec<u8>,
    ) -> Result<usize, Error> { ... }
}
Expand description

What an action can ask of its host.

Implemented twice: once for the real ABI inside a module, and once by crate::testing for a host on your own machine. It is public so that the two are visibly the same contract, and so a later phase can add a transport without changing what an action sees.

Required Methods§

Source

fn call(&self, name: String, params: Value) -> Result<Value, Error>

Run an action and answer with its result.

The envelope the host replies in is unwrapped here, so callers see either the result or a typed error and never a three-member document they have to inspect themselves.

Source

fn cast(&self, name: String, params: Value)

Run an action and do not wait for it.

Source

fn context(&self) -> Option<String>

The initial request payload, exactly as the host wrote it.

Provided Methods§

Source

fn call_bytes( &self, name: String, params: Value, into: &mut Vec<u8>, ) -> Result<usize, Error>

Run an action whose reply is a run of bytes, and append them to into.

Answers with how many bytes were appended. The bytes arrive as they are — no envelope, no text encoding — and a host that refused answers with a typed error instead, exactly as Transport::call does.

Provided, so a transport written before this method existed still compiles; the provided one refuses every such call.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§