Skip to content

Commit

Permalink
Merge pull request #582 from fuzzypixelz/must-use-publication
Browse files Browse the repository at this point in the history
Issue a diagnostic whenever `Publication` is not used
  • Loading branch information
p-avital authored Nov 7, 2023
2 parents a2cf2bf + 9191107 commit 9ea5dc1
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions commons/zenoh-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ impl<T, Output> Resolve<Output> for T where
}

// Closure to wait
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
pub struct ResolveClosure<C, To>(C)
where
To: Sized + Send,
Expand Down Expand Up @@ -120,6 +121,7 @@ where
}

// Future to wait
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
pub struct ResolveFuture<F, To>(F)
where
To: Sized + Send,
Expand Down
1 change: 1 addition & 0 deletions zenoh-ext/src/publication_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use zenoh_result::{bail, ZResult};
use zenoh_util::core::ResolveFuture;

/// The builder of PublicationCache, allowing to configure it.
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
pub struct PublicationCacheBuilder<'a, 'b, 'c> {
session: SessionRef<'a>,
pub_key_expr: ZResult<KeyExpr<'b>>,
Expand Down
3 changes: 3 additions & 0 deletions zenoh-ext/src/querying_subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use zenoh::SessionRef;
use zenoh_core::{zlock, AsyncResolve, Resolvable, SyncResolve};

/// The builder of [`FetchingSubscriber`], allowing to configure it.
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
pub struct QueryingSubscriberBuilder<'a, 'b, KeySpace, Handler> {
pub(crate) session: SessionRef<'a>,
pub(crate) key_expr: ZResult<KeyExpr<'b>>,
Expand Down Expand Up @@ -340,6 +341,7 @@ struct InnerState {
}

/// The builder of [`FetchingSubscriber`], allowing to configure it.
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
pub struct FetchingSubscriberBuilder<
'a,
'b,
Expand Down Expand Up @@ -850,6 +852,7 @@ impl Drop for RepliesHandler {
/// .unwrap();
/// # })
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
pub struct FetchBuilder<
Fetch: FnOnce(Box<dyn Fn(TryIntoSample) + Send + Sync>) -> ZResult<()>,
TryIntoSample,
Expand Down
3 changes: 3 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;
/// # })
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
pub struct ZidBuilder<'a> {
pub(crate) session: SessionRef<'a>,
}
Expand Down Expand Up @@ -67,6 +68,7 @@ impl<'a> AsyncResolve for ZidBuilder<'a> {
/// while let Some(router_zid) = routers_zid.next() {}
/// # })
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
pub struct RoutersZidBuilder<'a> {
pub(crate) session: SessionRef<'a>,
}
Expand Down Expand Up @@ -112,6 +114,7 @@ impl<'a> AsyncResolve for RoutersZidBuilder<'a> {
/// while let Some(peer_zid) = peers_zid.next() {}
/// # })
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
pub struct PeersZidBuilder<'a> {
pub(crate) session: SessionRef<'a>,
}
Expand Down
1 change: 1 addition & 0 deletions zenoh/src/key_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ impl<'a> Undeclarable<&'a Session, KeyExprUndeclaration<'a>> for KeyExpr<'a> {
/// session.undeclare(key_expr).res().await.unwrap();
/// # })
/// ```
#[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,
expr: KeyExpr<'a>,
Expand Down
1 change: 1 addition & 0 deletions zenoh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ pub fn init(runtime: Runtime) -> InitBuilder {
}

/// A builder returned by [`init`] and used to initialize a Session with an existing Runtime.
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[doc(hidden)]
#[zenoh_macros::unstable]
pub struct InitBuilder {
Expand Down
3 changes: 3 additions & 0 deletions zenoh/src/liveliness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ impl<'a> Liveliness<'a> {
/// .unwrap();
/// # })
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[zenoh_macros::unstable]
#[derive(Debug)]
pub struct LivelinessTokenBuilder<'a, 'b> {
Expand Down Expand Up @@ -310,6 +311,7 @@ pub struct LivelinessToken<'a> {
/// liveliness.undeclare().res().await.unwrap();
/// # })
/// ```
#[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> {
token: LivelinessToken<'a>,
Expand Down Expand Up @@ -595,6 +597,7 @@ where
/// }
/// # })
/// ```
#[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> {
pub(crate) session: &'a Session,
Expand Down
4 changes: 4 additions & 0 deletions zenoh/src/publication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub type DeleteBuilder<'a, 'b> = PutBuilder<'a, 'b>;
/// .unwrap();
/// # })
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[derive(Debug, Clone)]
pub struct PutBuilder<'a, 'b> {
pub(crate) publisher: PublisherBuilder<'a, 'b>,
Expand Down Expand Up @@ -362,6 +363,7 @@ impl<'a> Undeclarable<(), PublisherUndeclaration<'a>> for Publisher<'a> {
/// publisher.undeclare().res().await.unwrap();
/// # })
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
pub struct PublisherUndeclaration<'a> {
publisher: Publisher<'a>,
}
Expand Down Expand Up @@ -404,6 +406,7 @@ impl Drop for Publisher<'_> {

/// A [`Resolvable`] returned by [`Publisher::put()`](Publisher::put),
/// [`Publisher::delete()`](Publisher::delete) and [`Publisher::write()`](Publisher::write).
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
pub struct Publication<'a> {
publisher: &'a Publisher<'a>,
value: Value,
Expand Down Expand Up @@ -520,6 +523,7 @@ where
/// .unwrap();
/// # })
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[derive(Debug)]
pub struct PublisherBuilder<'a, 'b: 'a> {
pub(crate) session: SessionRef<'a>,
Expand Down
1 change: 1 addition & 0 deletions zenoh/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ pub(crate) struct QueryState {
/// }
/// # })
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[derive(Debug)]
pub struct GetBuilder<'a, 'b, Handler> {
pub(crate) session: &'a Session,
Expand Down
3 changes: 2 additions & 1 deletion zenoh/src/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ impl<'a> Undeclarable<(), QueryableUndeclaration<'a>> for CallbackQueryable<'a>
/// queryable.undeclare().res().await.unwrap();
/// # })
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
pub struct QueryableUndeclaration<'a> {
queryable: CallbackQueryable<'a>,
}
Expand Down Expand Up @@ -325,8 +326,8 @@ impl Drop for CallbackQueryable<'_> {
/// let queryable = session.declare_queryable("key/expression").res().await.unwrap();
/// # })
/// ```
#[derive(Debug)]
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[derive(Debug)]
pub struct QueryableBuilder<'a, 'b, Handler> {
pub(crate) session: SessionRef<'a>,
pub(crate) key_expr: ZResult<KeyExpr<'b>>,
Expand Down
3 changes: 2 additions & 1 deletion zenoh/src/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ impl<'a> Undeclarable<(), SubscriberUndeclaration<'a>> for SubscriberInner<'a> {
/// subscriber.undeclare().res().await.unwrap();
/// # })
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
pub struct SubscriberUndeclaration<'a> {
subscriber: SubscriberInner<'a>,
}
Expand Down Expand Up @@ -297,8 +298,8 @@ impl From<PushMode> for Mode {
/// .unwrap();
/// # })
/// ```
#[derive(Debug)]
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[derive(Debug)]
pub struct SubscriberBuilder<'a, 'b, Mode, Handler> {
#[cfg(feature = "unstable")]
pub session: SessionRef<'a>,
Expand Down

0 comments on commit 9ea5dc1

Please sign in to comment.