API alignment
Semantic and naming should be aligned across all zenoh API bindings: Rust, C, Python, and more to come.
Tracking upstream roadmap issue https://github.com/eclipse-zenoh/roadmap/issues/3
After some discussion, it was agreed by the zenoh team that the common behaviour for subscribe(), queryable(), and get() is to be based on callbacks.
This approach simplifies the bindings from Rust towards other programming languages (e.g., C, Python, Java, etc.).
Then , departing from those callbacks, is then possible to create a stream for all subscriptions, queries, and replies by using the most appropriate library and mechanism depending on the language.
In the particular case of Rust, taking as examples the subscribe() operation, we would have the following API for creating a subscriber:
// Subscriber operating on a callback
let sub = session.subscribe("/key/expression").callback(|s| ...);
// Subscriber providing back a stream based on a flume channel.
// Other channel implementations may be provided by the user.
let sub = session.subscribe("/key/expression").channel(flume::bounded(64));
Moreover, providing a default shortcut for subscribe() is also considered practical and more user-friendly:
// Shortcut for session.subscribe("/key/expression").channel(flume::bounded(64))
let sub = session.subscribe("/key/expression");
Update: the look-and-feel of the new API is captured in https://github.com/eclipse-zenoh/roadmap/discussions/23
API:
- [x] Move the
.forward(...)(from a subscriber to a publisher) from basic zenoh API to zenoh-ext - [x] Replace
.mode(...)in.declare_subscriber(...)builder with an option forSubMode::Pullreturning a dedicated builder for pull subscribers. - [ ] Return
HashMap<String, String>instead ofPropertiesin.info()
Examples:
- [x] Convert
z_pongfrom stream-based subscriber to callback-based subscriber - [x] Use
.declare_publisher()inz_pub_shm_thr - [ ] Add a stats report to
z_pub_thrwhen the test is finished - [ ] Bugfix
z_subkeyexpr arg - [ ] Use
.race()instead ofselect!in all examples - [x] Verify all examples work as expected
Merged into master.