Crate aldrin

source ·
Expand description

Aldrin client library

This library implements the client side of the Aldrin specification and can be used to connect to Aldrin brokers. It is fully asynchronous (async/await) and doesn’t depend on any specific async runtime.

Parts of this library should be considered low-level building blocks for the code that can be auto-generated from Aldrin schemas. As an example, performing a function call on a service requires knowing the function’s id and uses a polymorphic type to encode the function’s arguments. It is generally recommended to rely on the more ergonomic auto-generated code instead.

The first entry point is the Client and it’s connect method. Clients are parameterized over an AsyncTransport, which abstracts the low-level details of a transport, like e.g. TCP/IP.

After establishing a connection, the resulting Client must be continuously polled (through Client::run). One way to achieve this is to “spawn” it with an async runtime of your choice. Alternatively, it can also be polled manually.

While the Client is being polled, all interaction with it happens through a Handle, which can be acquired with Client::handle. The Client will automatically shut down (as in, the Client::run future will complete) when the last Handle has been dropped.

§Examples

use aldrin::Client;
use std::error::Error;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    // Create an AsyncTransport for connecting to the broker.
    // let async_transport = ...

    // Connect to the broker:
    let client = Client::connect(async_transport).await?;

    // Acquire a handle and spawn the client:
    let handle = client.handle().clone();
    let join = tokio::spawn(client.run());

    // The client is now fully connected and can be interacted with through the handle.

    // Shut down client:
    handle.shutdown();
    join.await??;

    Ok(())
}

Re-exports§

Modules§

Macros§

  • Generates code from an Aldrin schema.

Structs§

Enums§