Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature tags for feature matrices #693

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions commons/zenoh-protocol/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub struct Property {
}

/// The kind of a `Sample`.
// tags{publisher.write.kind}
#[repr(u8)]
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
pub enum SampleKind {
Expand Down Expand Up @@ -92,6 +93,7 @@ impl TryFrom<u64> for SampleKind {
}

/// The global unique id of a zenoh peer.
// tags{zenoh_id}
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct ZenohId(uhlc::ID);
Expand Down Expand Up @@ -345,6 +347,8 @@ impl TryFrom<u8> for Priority {
}
}

/// The reliability request of a subscriber.
// tags{enum.reliability}
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
#[repr(u8)]
pub enum Reliability {
Expand Down Expand Up @@ -422,6 +426,7 @@ pub enum ConsolidationMode {
}

/// The `zenoh::queryable::Queryable`s that should be target of a `zenoh::Session::get()`.
// tags{enum.query.target}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub enum QueryTarget {
#[default]
Expand Down
2 changes: 2 additions & 0 deletions commons/zenoh-protocol/src/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//

// ignore_tagging
pub mod declare;
pub mod oam;
pub mod push;
Expand Down
2 changes: 2 additions & 0 deletions commons/zenoh-protocol/src/scouting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//

// ignore_tagging
pub mod hello;
pub mod scout;

Expand Down
2 changes: 2 additions & 0 deletions commons/zenoh-protocol/src/transport/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//

// ignore_tagging
pub mod close;
pub mod fragment;
pub mod frame;
Expand Down
2 changes: 2 additions & 0 deletions commons/zenoh-protocol/src/zenoh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//

// ignore_tagging
pub mod ack;
pub mod del;
pub mod err;
Expand Down
5 changes: 5 additions & 0 deletions zenoh/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub type Callback<'a, T> = Dyn<dyn Fn(T) + Send + Sync + 'a>;
/// while granting you access to the receiver through the returned value via [`std::ops::Deref`] and [`std::ops::DerefMut`].
///
/// Any closure that accepts `T` can be converted into a pair of itself and `()`.
// ignore_tagging
pub trait IntoCallbackReceiverPair<'a, T> {
type Receiver;
fn into_cb_receiver_pair(self) -> (Callback<'a, T>, Self::Receiver);
Expand Down Expand Up @@ -56,6 +57,8 @@ impl<T: Send + 'static> IntoCallbackReceiverPair<'static, T>
)
}
}

// ignore_tagging
pub struct DefaultHandler;
impl<T: Send + 'static> IntoCallbackReceiverPair<'static, T> for DefaultHandler {
type Receiver = flume::Receiver<T>;
Expand All @@ -82,6 +85,7 @@ impl<T: Send + Sync + 'static> IntoCallbackReceiverPair<'static, T>

/// A function that can transform a [`FnMut`]`(T)` to
/// a [`Fn`]`(T)` with the help of a [`Mutex`](std::sync::Mutex).
// ignore_tagging
pub fn locked<T>(fnmut: impl FnMut(T)) -> impl Fn(T) {
let lock = std::sync::Mutex::new(fnmut);
move |x| zlock!(lock)(x)
Expand All @@ -96,6 +100,7 @@ pub fn locked<T>(fnmut: impl FnMut(T)) -> impl Fn(T) {
/// - `callback` will never be called once `drop` has started.
/// - `drop` will only be called **once**, and **after every** `callback` has ended.
/// - The two previous guarantees imply that `call` and `drop` are never called concurrently.
// ignore_tagging
pub struct CallbackPair<Callback, DropFn>
where
DropFn: FnMut() + Send + Sync + 'static,
Expand Down
7 changes: 7 additions & 0 deletions zenoh/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use zenoh_protocol::core::{WhatAmI, ZenohId};
/// let zid = session.info().zid().res().await;
/// # })
/// ```
// tags{}
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[derive(Debug)]
pub struct ZidBuilder<'a> {
Expand Down Expand Up @@ -69,6 +70,7 @@ impl<'a> AsyncResolve for ZidBuilder<'a> {
/// while let Some(router_zid) = routers_zid.next() {}
/// # })
/// ```
// tags{}
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[derive(Debug)]
pub struct RoutersZidBuilder<'a> {
Expand Down Expand Up @@ -116,6 +118,7 @@ impl<'a> AsyncResolve for RoutersZidBuilder<'a> {
/// while let Some(peer_zid) = peers_zid.next() {}
/// # })
/// ```
// tags{}
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[derive(Debug)]
pub struct PeersZidBuilder<'a> {
Expand Down Expand Up @@ -162,6 +165,7 @@ impl<'a> AsyncResolve for PeersZidBuilder<'a> {
/// let zid = info.zid().res().await;
/// # })
/// ```
// tags{}
pub struct SessionInfo<'a> {
pub(crate) session: SessionRef<'a>,
}
Expand All @@ -178,6 +182,7 @@ impl SessionInfo<'_> {
/// let zid = session.info().zid().res().await;
/// # })
/// ```
// tags{session.zid.get}
pub fn zid(&self) -> ZidBuilder<'_> {
ZidBuilder {
session: self.session.clone(),
Expand All @@ -197,6 +202,7 @@ impl SessionInfo<'_> {
/// while let Some(router_zid) = routers_zid.next() {}
/// # })
/// ```
// tags{session.routers.get}
pub fn routers_zid(&self) -> RoutersZidBuilder<'_> {
RoutersZidBuilder {
session: self.session.clone(),
Expand All @@ -215,6 +221,7 @@ impl SessionInfo<'_> {
/// while let Some(peer_zid) = peers_zid.next() {}
/// # })
/// ```
// tags{session.peers.get}
pub fn peers_zid(&self) -> PeersZidBuilder<'_> {
PeersZidBuilder {
session: self.session.clone(),
Expand Down
17 changes: 16 additions & 1 deletion zenoh/src/key_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ pub(crate) enum KeyExprInner<'a> {
/// A possibly-owned version of [`keyexpr`] that may carry optimisations for use with a [`Session`] that may have declared it.
///
/// Check [`keyexpr`]'s documentation for detailed explainations of the Key Expression Language.
///
// tags{keyexpr}
#[repr(transparent)]
#[derive(Clone, serde::Deserialize, serde::Serialize)]
#[serde(from = "OwnedKeyExpr")]
Expand All @@ -74,6 +76,7 @@ impl KeyExpr<'static> {
/// # Safety
/// Key Expressions must follow some rules to be accepted by a Zenoh network.
/// Messages addressed with invalid key expressions will be dropped.
// tags{keyexpr.create.from_string_unchecked}
pub unsafe fn from_string_unchecked(s: String) -> Self {
Self(KeyExprInner::Owned(OwnedKeyExpr::from_string_unchecked(s)))
}
Expand All @@ -82,6 +85,7 @@ impl KeyExpr<'static> {
/// # Safety
/// Key Expressions must follow some rules to be accepted by a Zenoh network.
/// Messages addressed with invalid key expressions will be dropped.
// tags{keyexpr.create.from_string_unchecked}
pub unsafe fn from_boxed_string_unchecked(s: Box<str>) -> Self {
Self(KeyExprInner::Owned(
OwnedKeyExpr::from_boxed_string_unchecked(s),
Expand All @@ -95,6 +99,7 @@ impl<'a> KeyExpr<'a> {
/// Note that to be considered a valid key expression, a string MUST be canon.
///
/// [`KeyExpr::autocanonize`] is an alternative constructor that will canonize the passed expression before constructing it.
// tags{keyexpr.create}
pub fn new<T, E>(t: T) -> Result<Self, E>
where
Self: TryFrom<T, Error = E>,
Expand All @@ -105,6 +110,7 @@ impl<'a> KeyExpr<'a> {
/// Constructs a new [`KeyExpr`] aliasing `self`.
///
/// Note that [`KeyExpr`] (as well as [`OwnedKeyExpr`]) use reference counters internally, so you're probably better off using clone.
// ignore_tagging
pub fn borrowing_clone(&'a self) -> Self {
let inner = match &self.0 {
KeyExprInner::Borrowed(key_expr) => KeyExprInner::Borrowed(key_expr),
Expand Down Expand Up @@ -142,6 +148,7 @@ impl<'a> KeyExpr<'a> {
/// Canonizes the passed value before returning it as a `KeyExpr`.
///
/// Will return Err if the passed value isn't a valid key expression despite canonization.
// tags{keyexpr.autocanonize}
pub fn autocanonize<T, E>(mut t: T) -> Result<Self, E>
where
Self: TryFrom<T, Error = E>,
Expand All @@ -155,16 +162,19 @@ impl<'a> KeyExpr<'a> {
/// # Safety
/// Key Expressions must follow some rules to be accepted by a Zenoh network.
/// Messages addressed with invalid key expressions will be dropped.
pub unsafe fn from_str_uncheckend(s: &'a str) -> Self {
// tags{keyexpr.create.from_string_unchecked}
pub unsafe fn from_str_unchecked(s: &'a str) -> Self {
keyexpr::from_str_unchecked(s).into()
}

/// Returns the borrowed version of `self`
// ignore_tagging
pub fn as_keyexpr(&self) -> &keyexpr {
self
}

/// Ensures `self` owns all of its data, and informs rustc that it does.
// ignore_tagging
pub fn into_owned(self) -> KeyExpr<'static> {
match self.0 {
KeyExprInner::Borrowed(s) => KeyExpr(KeyExprInner::Owned(s.into())),
Expand Down Expand Up @@ -210,6 +220,7 @@ impl<'a> KeyExpr<'a> {
/// let workspace: KeyExpr = get_workspace();
/// let topic = workspace.join("some/topic").unwrap();
/// ```
// tags{keyexpr.join}
pub fn join<S: AsRef<str> + ?Sized>(&self, s: &S) -> ZResult<KeyExpr<'static>> {
let r = self.as_keyexpr().join(s)?;
if let KeyExprInner::Wire {
Expand All @@ -235,6 +246,7 @@ impl<'a> KeyExpr<'a> {
/// Performs string concatenation and returns the result as a [`KeyExpr`] if possible.
///
/// You should probably prefer [`KeyExpr::join`] as Zenoh may then take advantage of the hierachical separation it inserts.
// tags{keyexpr.concat}
pub fn concat<S: AsRef<str> + ?Sized>(&self, s: &S) -> ZResult<KeyExpr<'static>> {
let s = s.as_ref();
self._concat(s)
Expand Down Expand Up @@ -272,13 +284,15 @@ impl<'a> KeyExpr<'a> {
}
}

// tags{selector.create.from_keyexpr}
pub fn with_parameters(self, selector: &'a str) -> Selector<'a> {
Selector {
key_expr: self,
parameters: selector.into(),
}
}

// tags{selector.create.from_keyexpr}
pub fn with_owned_parameters(self, selector: String) -> Selector<'a> {
Selector {
key_expr: self,
Expand Down Expand Up @@ -584,6 +598,7 @@ impl<'a> Undeclarable<&'a Session, KeyExprUndeclaration<'a>> for KeyExpr<'a> {
/// session.undeclare(key_expr).res().await.unwrap();
/// # })
/// ```
// ignore_tagging
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
pub struct KeyExprUndeclaration<'a> {
session: &'a Session,
Expand Down
10 changes: 10 additions & 0 deletions zenoh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub use zenoh_result::ZResult as Result;

const GIT_VERSION: &str = git_version!(prefix = "v", cargo_prefix = "v");

// ignore_tagging
pub const FEATURES: &str = concat_enabled_features!(
prefix = "zenoh",
features = [
Expand Down Expand Up @@ -160,6 +161,7 @@ pub mod time {
/// Generates a reception [`Timestamp`] with id=0x01.
/// This operation should be called if a timestamp is required for an incoming [`zenoh::Sample`](crate::Sample)
/// that doesn't contain any timestamp.
// tags{timestamp.create}
pub fn new_reception_timestamp() -> Timestamp {
use std::time::{SystemTime, UNIX_EPOCH};

Expand All @@ -176,6 +178,7 @@ pub mod properties {
/// Convert a set of [`Properties`] into a [`Value`].
/// For instance, Properties: `[("k1", "v1"), ("k2, v2")]`
/// is converted into Json: `{ "k1": "v1", "k2": "v2" }`
// tags{value.create.from_properties}
pub fn properties_to_json_value(props: &Properties) -> Value {
let json_map = props
.iter()
Expand Down Expand Up @@ -214,6 +217,7 @@ pub mod scouting;
/// }
/// # })
/// ```
// tags{scout}
pub fn scout<I: Into<WhatAmIMatcher>, TryIntoConfig>(
what: I,
config: TryIntoConfig,
Expand Down Expand Up @@ -257,6 +261,7 @@ where
/// let session = zenoh::open(config).res().await.unwrap();
/// # })
/// ```
// tags{session.create}
pub fn open<TryIntoConfig>(config: TryIntoConfig) -> OpenBuilder<TryIntoConfig>
where
TryIntoConfig: std::convert::TryInto<crate::config::Config> + Send + 'static,
Expand All @@ -275,6 +280,7 @@ where
/// let session = zenoh::open(config::peer()).res().await.unwrap();
/// # })
/// ```
// ignore_tagging
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
pub struct OpenBuilder<TryIntoConfig>
where
Expand Down Expand Up @@ -320,6 +326,7 @@ where

/// Initialize a Session with an existing Runtime.
/// This operation is used by the plugins to share the same Runtime as the router.
// ignore_tagging
#[doc(hidden)]
#[zenoh_macros::unstable]
pub fn init(runtime: Runtime) -> InitBuilder {
Expand All @@ -331,6 +338,7 @@ pub fn init(runtime: Runtime) -> InitBuilder {
}

/// A builder returned by [`init`] and used to initialize a Session with an existing Runtime.
// ignore_tagging
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[doc(hidden)]
#[zenoh_macros::unstable]
Expand All @@ -343,12 +351,14 @@ pub struct InitBuilder {
#[zenoh_macros::unstable]
impl InitBuilder {
#[inline]
// ignore_tagging
pub fn aggregated_subscribers(mut self, exprs: Vec<OwnedKeyExpr>) -> Self {
self.aggregated_subscribers = exprs;
self
}

#[inline]
// ignore_tagging
pub fn aggregated_publishers(mut self, exprs: Vec<OwnedKeyExpr>) -> Self {
self.aggregated_publishers = exprs;
self
Expand Down
Loading
Loading