Crate zenoh

source ·
Expand description

Zenoh /zeno/ is a stack that unifies data in motion, data at rest and computations. It elegantly blends traditional pub/sub with geo distributed storage, queries and computations, while retaining a level of time and space efficiency that is well beyond any of the mainstream stacks.

Before delving into the examples, we need to introduce few Zenoh concepts. First off, in Zenoh you will deal with Resources, where a resource is made up of a key and a value. The other concept you’ll have to familiarize yourself with are key expressions, such as robot/sensor/temp, robot/sensor/*, robot/**, etc. As you can gather, the above key expression denotes set of keys, while the * and ** are wildcards representing respectively (1) an arbitrary string of characters, with the exclusion of the / separator, and (2) an arbitrary sequence of characters including separators.

Below are some examples that highlight these key concepts and show how easy it is to get started with.

§Examples

§Publishing Data

The example below shows how to produce a value for a key expression.

use zenoh::prelude::r#async::*;

#[tokio::main]
async fn main() {
    let session = zenoh::open(config::default()).res().await.unwrap();
    session.put("key/expression", "value").res().await.unwrap();
    session.close().res().await.unwrap();
}

§Subscribe

The example below shows how to consume values for a key expresison.

use futures::prelude::*;
use zenoh::prelude::r#async::*;

#[tokio::main]
async fn main() {
    let session = zenoh::open(config::default()).res().await.unwrap();
    let subscriber = session.declare_subscriber("key/expression").res().await.unwrap();
    while let Ok(sample) = subscriber.recv_async().await {
        println!("Received: {}", sample);
    };
}

§Query

The example below shows how to make a distributed query to collect the values associated with the resources whose key match the given key expression.

use futures::prelude::*;
use zenoh::prelude::r#async::*;

#[tokio::main]
async fn main() {
    let session = zenoh::open(config::default()).res().await.unwrap();
    let replies = session.get("key/expression").res().await.unwrap();
    while let Ok(reply) = replies.recv_async().await {
        println!(">> Received {:?}", reply.sample);
    }
}

Re-exports§

Modules§

Macros§

  • Equivalent to keyexpr::new, but the check is run at compile-time and will throw a compile error in case of failure.
  • Create format modules from a format specification.
  • Write a set of values into a Formatter and then builds it into an OwnedKeyExpr, stopping as soon as a value doesn’t fit the specification for its field.
  • Write a set of values into a Formatter, stopping as soon as a value doesn’t fit the specification for its field. Contrary to keformat doesn’t build the Formatter into a Key Expression.

Structs§

Enums§

Constants§

Traits§

Functions§

Type Aliases§