From 87fd3b9bb527eff0518491f7e9e3a4efa3ca30ea Mon Sep 17 00:00:00 2001 From: wyfo Date: Thu, 12 Sep 2024 09:07:27 +0000 Subject: [PATCH] deploy: 1e084743762503b3ad98f80f9584775438f23661 --- docs/migration_1.0/rust/index.html | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/docs/migration_1.0/rust/index.html b/docs/migration_1.0/rust/index.html index 867b2938..da137c93 100644 --- a/docs/migration_1.0/rust/index.html +++ b/docs/migration_1.0/rust/index.html @@ -1,6 +1,6 @@ Rust · Zenoh - pub/sub, geo distributed storage, query

Rust

Module reorganization

We reorganized the module tree, so import paths are not the same as before. The main difference is that everything should be imported via the root path zenoh::. Here are some examples, but you can look into zenoh/src/lib.rs for the complete list of changes.

// common use
+

Rust

Module reorganization

We reorganized the module tree, so import paths are not the same as before. The main difference is that everything should be imported via the root path zenoh::. Here are some examples, but you can look into zenoh/src/lib.rs for the complete list of changes.

// common use
 use zenoh::config::*;
 use zenoh::{Config, Error, Result};
 
@@ -71,23 +71,7 @@
 // **when all remaining data has been processed**.
 // subscriber undeclaration has not been sent on the wire
 subscriber_task.await.unwrap()
-

Callbacks run in background until session is closed

Session entities, e.g. subscribers, declared with callbacks are no more undeclared when they are dropped; there is no more need to keep a variable around when the intent is to have it run until the session is closed.

let session = zenoh::open(zenoh::config::peer()).await. unwrap();
-session
-    .declare_subscriber("key/ expression")
-    .callback(|sample| { println!("Received: {} {:?}", sample. key_expr(), sample. payload()) })
-    .await
-    .unwrap();
-// subscriber run in background until the session is closed
-// no need to keep a variable around
-

If you still want the entity to be undeclared when dropped, you can simply use with instead of callback; it may just require you to annotate the callback, as type inference is not as good as with callback method.

let session = zenoh::open(zenoh::config::peer()).await. unwrap();
-let subscriber = session
-    .declare_subscriber("key/ expression")
-    // annotation needed
-    .with(|sample: Sample| { println!("Received: {} {:?}", sample. key_expr(), sample. payload()) })
-    .await
-    .unwrap();
-// subscriber is undeclared when dropped
-

Going into details, a new method undeclare_on_drop(bool) – default to true, has been added to the builders, and callback(cb) is now simply a shortcut to with(cb).undeclare_on_drop(false). You should rarely need to call this method directly however.

Value is gone, long live ZBytes

We have replaced Value with ZBytes and Encoding , and added a number of conversion implementations such that user structs can be serialized into ZBytes, sent via Zenoh, and de-serialized from ZBytes with ease.

This is facilitated through the ZSerde struct, and implementations of the traits +

Value is gone, long live ZBytes

We have replaced Value with ZBytes and Encoding , and added a number of conversion implementations such that user structs can be serialized into ZBytes, sent via Zenoh, and de-serialized from ZBytes with ease.

This is facilitated through the ZSerde struct, and implementations of the traits zenoh::bytes::Deserialize and zenoh::bytes::Serialize.

We provide implementations of Zenoh’s aforementioned Deserialize and Serialize traits for primitive Rust types, Rust’s Vec, the Value type exposed by Serde’s various libraries as well as an example of Protobuf ’s prost::Message type.

You can look at a full set of examples in examples/examples/z_bytes.rs.

NOTE: ⚠️ ZSerde is not the only serializer/deserializer users can make use of, nor a limitation to the types supported by Zenoh. Users are free to use whichever serializer/deserializer they wish!

  • Zenoh 0.11.x
let sample = subscriber.recv_async().await.unwrap();
 let value: Value = sample.value;
 let the_string: String = value.try_into().unwrap();