Skip to content

Commit

Permalink
more tags
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin committed Feb 4, 2024
1 parent b7dcc29 commit 5ac6795
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 2 deletions.
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
17 changes: 16 additions & 1 deletion zenoh/src/key_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,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 @@ -75,6 +77,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.from_unchecked}
pub unsafe fn from_string_unchecked(s: String) -> Self {
Self(KeyExprInner::Owned(OwnedKeyExpr::from_string_unchecked(s)))
}
Expand All @@ -83,6 +86,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.from_unchecked}
pub unsafe fn from_boxed_string_unchecked(s: Box<str>) -> Self {
Self(KeyExprInner::Owned(
OwnedKeyExpr::from_boxed_string_unchecked(s),
Expand All @@ -96,6 +100,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.new}
pub fn new<T, E>(t: T) -> Result<Self, E>
where
Self: TryFrom<T, Error = E>,
Expand All @@ -106,6 +111,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 @@ -143,6 +149,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 @@ -156,16 +163,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.from_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 @@ -211,6 +221,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 @@ -236,6 +247,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 @@ -273,13 +285,15 @@ impl<'a> KeyExpr<'a> {
}
}

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

// tags{keyexpr.with_parameters}
pub fn with_owned_parameters(self, selector: String) -> Selector<'a> {
Selector {
key_expr: self,
Expand Down Expand Up @@ -585,6 +599,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{time.new_reception_timestamp}
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{properties.properties_to_json_value}
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.open}
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
17 changes: 17 additions & 0 deletions zenoh/src/liveliness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ lazy_static::lazy_static!(
/// .unwrap();
/// # })
/// ```
// tags{liveliness}
#[zenoh_macros::unstable]
pub struct Liveliness<'a> {
pub(crate) session: SessionRef<'a>,
Expand Down Expand Up @@ -104,6 +105,7 @@ impl<'a> Liveliness<'a> {
/// # })
/// ```
#[zenoh_macros::unstable]
// tags{liveliness.declare_token}
pub fn declare_token<'b, TryIntoKeyExpr>(
&self,
key_expr: TryIntoKeyExpr,
Expand Down Expand Up @@ -139,6 +141,7 @@ impl<'a> Liveliness<'a> {
/// }
/// # })
/// ```
// tags{liveliness.declare_subscriber}
#[zenoh_macros::unstable]
pub fn declare_subscriber<'b, TryIntoKeyExpr>(
&self,
Expand Down Expand Up @@ -175,6 +178,7 @@ impl<'a> Liveliness<'a> {
/// }
/// # })
/// ```
// tags{liveliness.get}
#[zenoh_macros::unstable]
pub fn get<'b: 'a, TryIntoKeyExpr>(
&'a self,
Expand Down Expand Up @@ -214,6 +218,7 @@ impl<'a> Liveliness<'a> {
/// .unwrap();
/// # })
/// ```
// ignore_tagging
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[zenoh_macros::unstable]
#[derive(Debug)]
Expand Down Expand Up @@ -288,6 +293,7 @@ pub(crate) struct LivelinessTokenState {
/// .unwrap();
/// # })
/// ```
// tags{liveliness.token}
#[zenoh_macros::unstable]
#[derive(Debug)]
pub struct LivelinessToken<'a> {
Expand All @@ -314,6 +320,7 @@ pub struct LivelinessToken<'a> {
/// liveliness.undeclare().res().await.unwrap();
/// # })
/// ```
// ignore_tagging
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[zenoh_macros::unstable]
pub struct LivelinessTokenUndeclaration<'a> {
Expand Down Expand Up @@ -366,6 +373,7 @@ impl<'a> LivelinessToken<'a> {
/// liveliness.undeclare().res().await.unwrap();
/// # })
/// ```
// tags{liveliness.token.undeclare}
#[inline]
pub fn undeclare(self) -> impl Resolve<ZResult<()>> + 'a {
Undeclarable::undeclare_inner(self, ())
Expand Down Expand Up @@ -405,6 +413,7 @@ impl Drop for LivelinessToken<'_> {
/// .unwrap();
/// # })
/// ```
// ignore_tagging
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[zenoh_macros::unstable]
#[derive(Debug)]
Expand Down Expand Up @@ -432,6 +441,7 @@ impl<'a, 'b> LivelinessSubscriberBuilder<'a, 'b, DefaultHandler> {
/// .unwrap();
/// # })
/// ```
// tags{liveliness.subscriber.callback}
#[inline]
#[zenoh_macros::unstable]
pub fn callback<Callback>(
Expand Down Expand Up @@ -473,6 +483,7 @@ impl<'a, 'b> LivelinessSubscriberBuilder<'a, 'b, DefaultHandler> {
/// .unwrap();
/// # })
/// ```
// tags{liveliness.subscriber.callback}
#[inline]
#[zenoh_macros::unstable]
pub fn callback_mut<CallbackMut>(
Expand Down Expand Up @@ -504,6 +515,7 @@ impl<'a, 'b> LivelinessSubscriberBuilder<'a, 'b, DefaultHandler> {
/// }
/// # })
/// ```
// tags{liveliness.subscriber.pipe}
#[inline]
#[zenoh_macros::unstable]
pub fn with<Handler>(self, handler: Handler) -> LivelinessSubscriberBuilder<'a, 'b, Handler>
Expand Down Expand Up @@ -600,6 +612,7 @@ where
/// }
/// # })
/// ```
// ignore_tagging
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[derive(Debug)]
pub struct LivelinessGetBuilder<'a, 'b, Handler> {
Expand Down Expand Up @@ -627,6 +640,7 @@ impl<'a, 'b> LivelinessGetBuilder<'a, 'b, DefaultHandler> {
/// .unwrap();
/// # })
/// ```
// tags{liveiness.get.callback}
#[inline]
pub fn callback<Callback>(self, callback: Callback) -> LivelinessGetBuilder<'a, 'b, Callback>
where
Expand Down Expand Up @@ -667,6 +681,7 @@ impl<'a, 'b> LivelinessGetBuilder<'a, 'b, DefaultHandler> {
/// .unwrap();
/// # })
/// ```
// tags{liveiness.get.callback}
#[inline]
pub fn callback_mut<CallbackMut>(
self,
Expand Down Expand Up @@ -698,6 +713,7 @@ impl<'a, 'b> LivelinessGetBuilder<'a, 'b, DefaultHandler> {
/// }
/// # })
/// ```
// tags{liveiness.get.pipe}
#[inline]
pub fn with<Handler>(self, handler: Handler) -> LivelinessGetBuilder<'a, 'b, Handler>
where
Expand All @@ -720,6 +736,7 @@ impl<'a, 'b> LivelinessGetBuilder<'a, 'b, DefaultHandler> {

impl<'a, 'b, Handler> LivelinessGetBuilder<'a, 'b, Handler> {
/// Set query timeout.
// tags{liveiness.get.timeout}
#[inline]
pub fn timeout(mut self, timeout: Duration) -> Self {
self.timeout = timeout;
Expand Down
2 changes: 2 additions & 0 deletions zenoh/src/net/codec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
//
pub(crate) mod linkstate;

// ignore_tagging
#[derive(Clone, Copy)]
pub struct Zenoh080Routing;

impl Zenoh080Routing {
// ignore_tagging
pub const fn new() -> Self {
Self
}
Expand Down
3 changes: 3 additions & 0 deletions zenoh/src/net/routing/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use zenoh_protocol::{
use zenoh_transport::stats::TransportStats;
use zenoh_transport::{multicast::TransportMulticast, primitives::Primitives};

// ignore_tagging
pub struct FaceState {
pub(super) id: usize,
pub(super) zid: ZenohId,
Expand Down Expand Up @@ -83,6 +84,7 @@ impl FaceState {

#[allow(dead_code)]
#[inline]
// ignore_tagging
pub fn is_local(&self) -> bool {
self.local
}
Expand Down Expand Up @@ -159,6 +161,7 @@ impl fmt::Display for FaceState {
}
}

// ignore_tagging
#[derive(Clone)]
pub struct Face {
pub(crate) tables: Arc<TablesLock>,
Expand Down
Loading

0 comments on commit 5ac6795

Please sign in to comment.