Skip to content

Commit

Permalink
Remove SyncResolve and AsyncResolve
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzypixelz committed Sep 20, 2024
1 parent 1e17a31 commit bc53620
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 103 deletions.
62 changes: 3 additions & 59 deletions commons/zenoh-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,68 +54,12 @@ pub trait Wait: Resolvable {
fn wait(self) -> Self::To;
}

#[deprecated(since = "1.0.0", note = "use `.await` directly instead")]
pub trait AsyncResolve: Resolvable {
type Future: Future<Output = Self::To> + Send;

#[allow(deprecated)]
#[deprecated(since = "1.0.0", note = "use `.await` directly instead")]
fn res_async(self) -> Self::Future;

#[allow(deprecated)]
#[deprecated(since = "1.0.0", note = "use `zenoh::Wait::wait` instead")]
fn res(self) -> Self::Future
where
Self: Sized,
{
self.res_async()
}
}

#[allow(deprecated)]
impl<T> AsyncResolve for T
where
T: Resolvable + IntoFuture<Output = Self::To>,
T::IntoFuture: Send,
{
type Future = T::IntoFuture;

fn res_async(self) -> Self::Future {
self.into_future()
}
}

#[deprecated(since = "1.0.0", note = "use `zenoh::Wait` instead")]
pub trait SyncResolve: Resolvable {
#[deprecated(since = "1.0.0", note = "use `zenoh::Wait::wait` instead")]
fn res_sync(self) -> Self::To;

#[allow(deprecated)]
#[deprecated(since = "1.0.0", note = "use `zenoh::Wait::wait` instead")]
fn res(self) -> Self::To
where
Self: Sized,
{
self.res_sync()
}
}

#[allow(deprecated)]
impl<T> SyncResolve for T
where
T: Wait,
{
fn res_sync(self) -> Self::To {
self.wait()
}
}

/// Zenoh's trait for resolving builder patterns.
///
/// Builder patterns in Zenoh can be resolved by awaiting them, in async context,
/// and [`Wait::wait`] in sync context.
/// We advise to prefer the usage of asynchronous execution, and to use synchronous one with caution
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or synchronous `.wait()` method"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
pub trait Resolve<Output>:
Resolvable<To = Output>
+ Wait
Expand All @@ -135,7 +79,7 @@ impl<T, Output> Resolve<Output> for T where
}

// Closure to wait
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or synchronous `.wait()` method"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
pub struct ResolveClosure<C, To>(C)
where
To: Sized + Send,
Expand Down Expand Up @@ -183,7 +127,7 @@ where
}

// Future to wait
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or synchronous `.wait()` method"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
pub struct ResolveFuture<F, To>(F)
where
To: Sized + Send,
Expand Down
2 changes: 1 addition & 1 deletion zenoh-ext/src/publication_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use zenoh::{
};

/// 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`"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
pub struct PublicationCacheBuilder<'a, 'b, 'c> {
session: &'a Session,
pub_key_expr: ZResult<KeyExpr<'b>>,
Expand Down
6 changes: 3 additions & 3 deletions zenoh-ext/src/querying_subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use zenoh::{
use crate::ExtractSample;

/// 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`"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
pub struct QueryingSubscriberBuilder<'a, 'b, KeySpace, Handler> {
pub(crate) session: &'a Session,
pub(crate) key_expr: ZResult<KeyExpr<'b>>,
Expand Down Expand Up @@ -362,7 +362,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`"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
pub struct FetchingSubscriberBuilder<
'a,
'b,
Expand Down Expand Up @@ -880,7 +880,7 @@ impl Drop for RepliesHandler {
/// .unwrap();
/// # }
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
pub struct FetchBuilder<
Fetch: FnOnce(Box<dyn Fn(TryIntoSample) + Send + Sync>) -> ZResult<()>,
TryIntoSample,
Expand Down
4 changes: 2 additions & 2 deletions zenoh/src/api/builders/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub struct PublicationBuilderDelete;
/// .unwrap();
/// # }
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
#[derive(Debug, Clone)]
pub struct PublicationBuilder<P, T> {
pub(crate) publisher: P,
Expand Down Expand Up @@ -279,7 +279,7 @@ impl IntoFuture for PublicationBuilder<PublisherBuilder<'_, '_>, PublicationBuil
/// .unwrap();
/// # }
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
#[derive(Debug)]
pub struct PublisherBuilder<'a, 'b> {
pub(crate) session: &'a Session,
Expand Down
6 changes: 3 additions & 3 deletions zenoh/src/api/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use crate::net::runtime::Runtime;
/// let zid = session.info().zid().await;
/// # }
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
pub struct ZenohIdBuilder<'a> {
runtime: &'a Runtime,
}
Expand Down Expand Up @@ -71,7 +71,7 @@ impl<'a> IntoFuture for ZenohIdBuilder<'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`"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
pub struct RoutersZenohIdBuilder<'a> {
runtime: &'a Runtime,
}
Expand Down Expand Up @@ -119,7 +119,7 @@ impl<'a> IntoFuture for RoutersZenohIdBuilder<'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`"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
pub struct PeersZenohIdBuilder<'a> {
runtime: &'a Runtime,
}
Expand Down
2 changes: 1 addition & 1 deletion zenoh/src/api/key_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ impl<'a> UndeclarableSealed<&'a Session> for KeyExpr<'a> {
/// session.undeclare(key_expr).await.unwrap();
/// # }
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
pub struct KeyExprUndeclaration<'a> {
session: &'a Session,
expr: KeyExpr<'a>,
Expand Down
8 changes: 4 additions & 4 deletions zenoh/src/api/liveliness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl<'a> Liveliness<'a> {
/// .unwrap();
/// # }
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
#[zenoh_macros::unstable]
#[derive(Debug)]
pub struct LivelinessTokenBuilder<'a, 'b> {
Expand Down Expand Up @@ -328,7 +328,7 @@ pub struct LivelinessToken {
/// liveliness.undeclare().await.unwrap();
/// # }
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
#[zenoh_macros::unstable]
pub struct LivelinessTokenUndeclaration(LivelinessToken);

Expand Down Expand Up @@ -420,7 +420,7 @@ impl Drop for LivelinessToken {
/// .unwrap();
/// # }
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
#[zenoh_macros::unstable]
#[derive(Debug)]
pub struct LivelinessSubscriberBuilder<'a, 'b, Handler> {
Expand Down Expand Up @@ -645,7 +645,7 @@ where
/// }
/// # }
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
#[derive(Debug)]
pub struct LivelinessGetBuilder<'a, 'b, Handler> {
pub(crate) session: &'a Session,
Expand Down
2 changes: 1 addition & 1 deletion zenoh/src/api/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ impl<'a> UndeclarableSealed<()> for Publisher<'a> {
/// publisher.undeclare().await.unwrap();
/// # }
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
pub struct PublisherUndeclaration<'a>(Publisher<'a>);

impl Resolvable for PublisherUndeclaration<'_> {
Expand Down
2 changes: 1 addition & 1 deletion zenoh/src/api/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl QueryState {
/// }
/// # }
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
#[derive(Debug)]
pub struct SessionGetBuilder<'a, 'b, Handler> {
pub(crate) session: &'a Session,
Expand Down
8 changes: 4 additions & 4 deletions zenoh/src/api/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ pub struct ReplyBuilderPut {
pub struct ReplyBuilderDelete;

/// A builder returned by [`Query::reply()`](Query::reply) and [`Query::reply_del()`](Query::reply_del)
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
#[derive(Debug)]
pub struct ReplyBuilder<'a, 'b, T> {
query: &'a Query,
Expand Down Expand Up @@ -468,7 +468,7 @@ impl IntoFuture for ReplyBuilder<'_, '_, ReplyBuilderDelete> {
}

/// A builder returned by [`Query::reply_err()`](Query::reply_err).
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
#[derive(Debug)]
pub struct ReplyErrBuilder<'a> {
query: &'a Query,
Expand Down Expand Up @@ -562,7 +562,7 @@ pub(crate) struct QueryableInner {
/// queryable.undeclare().await.unwrap();
/// # }
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
pub struct QueryableUndeclaration<Handler>(Queryable<Handler>);

impl<Handler> Resolvable for QueryableUndeclaration<Handler> {
Expand Down Expand Up @@ -595,7 +595,7 @@ impl<Handler> IntoFuture for QueryableUndeclaration<Handler> {
/// let queryable = session.declare_queryable("key/expression").await.unwrap();
/// # }
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
#[derive(Debug)]
pub struct QueryableBuilder<'a, 'b, Handler> {
pub(crate) session: &'a Session,
Expand Down
2 changes: 1 addition & 1 deletion zenoh/src/api/scouting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use crate::{
/// }
/// # }
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
#[derive(Debug)]
pub struct ScoutBuilder<Handler> {
pub(crate) what: WhatAmIMatcher,
Expand Down
4 changes: 2 additions & 2 deletions zenoh/src/api/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2855,7 +2855,7 @@ where
/// let session = zenoh::open(zenoh::Config::default()).await.unwrap();
/// # }
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
pub struct OpenBuilder<TryIntoConfig>
where
TryIntoConfig: std::convert::TryInto<crate::config::Config> + Send + 'static,
Expand Down Expand Up @@ -2930,7 +2930,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`"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
#[doc(hidden)]
#[zenoh_macros::internal]
pub struct InitBuilder {
Expand Down
4 changes: 2 additions & 2 deletions zenoh/src/api/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub(crate) struct SubscriberInner {
/// subscriber.undeclare().await.unwrap();
/// # }
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
pub struct SubscriberUndeclaration<Handler>(Subscriber<Handler>);

impl<Handler> Resolvable for SubscriberUndeclaration<Handler> {
Expand Down Expand Up @@ -111,7 +111,7 @@ impl<Handler> IntoFuture for SubscriberUndeclaration<Handler> {
/// .unwrap();
/// # }
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"]
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
#[derive(Debug)]
pub struct SubscriberBuilder<'a, 'b, Handler> {
#[cfg(feature = "internal")]
Expand Down
2 changes: 0 additions & 2 deletions zenoh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ pub const FEATURES: &str = zenoh_util::concat_enabled_features!(
]
);

#[allow(deprecated)]
pub use zenoh_core::{AsyncResolve, SyncResolve};
pub use zenoh_core::{Resolvable, Resolve, Wait};
/// A zenoh error.
pub use zenoh_result::Error;
Expand Down
17 changes: 0 additions & 17 deletions zenoh/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,4 @@
//! use zenoh::prelude::*;
//! ```
#[allow(deprecated)]
pub use crate::AsyncResolve;
#[allow(deprecated)]
pub use crate::SyncResolve;
pub use crate::Wait;

/// Prelude to import when using Zenoh's sync API.
#[deprecated(since = "1.0.0", note = "use `zenoh::Wait` instead")]
pub mod sync {
#[allow(deprecated)]
pub use crate::SyncResolve;
}
/// Prelude to import when using Zenoh's async API.
#[deprecated(since = "1.0.0")]
pub mod r#async {
#[allow(deprecated)]
pub use crate::AsyncResolve;
}

0 comments on commit bc53620

Please sign in to comment.