Skip to content

Commit

Permalink
typedefs for complex builder types (#890)
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin authored Apr 5, 2024
1 parent 23931f9 commit 8f8eb25
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
21 changes: 15 additions & 6 deletions zenoh/src/publication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ pub struct PublicationBuilderPut {
#[derive(Debug, Clone)]
pub struct PublicationBuilderDelete;

/// A builder for initializing a [`put`](crate::Session::put) and [`delete`](crate::Session::delete) operations
/// A builder for initializing [`Session::put`](crate::Session::put), [`Session::delete`](crate::Session::delete),
/// [`Publisher::put`](crate::Publisher::put), and [`Publisher::delete`](crate::Publisher::delete) operations.
///
/// # Examples
/// ```
Expand Down Expand Up @@ -78,6 +79,17 @@ pub struct PublicationBuilder<P, T> {
pub(crate) attachment: Option<Attachment>,
}

pub type SessionPutBuilder<'a, 'b> =
PublicationBuilder<PublisherBuilder<'a, 'b>, PublicationBuilderPut>;

pub type SessionDeleteBuilder<'a, 'b> =
PublicationBuilder<PublisherBuilder<'a, 'b>, PublicationBuilderDelete>;

pub type PublisherPutBuilder<'a> = PublicationBuilder<&'a Publisher<'a>, PublicationBuilderPut>;

pub type PublisherDeleteBuilder<'a> =
PublicationBuilder<&'a Publisher<'a>, PublicationBuilderDelete>;

impl<T> QoSBuilderTrait for PublicationBuilder<PublisherBuilder<'_, '_>, T> {
#[inline]
fn congestion_control(self, congestion_control: CongestionControl) -> Self {
Expand Down Expand Up @@ -405,10 +417,7 @@ impl<'a> Publisher<'a> {
/// # }
/// ```
#[inline]
pub fn put<IntoPayload>(
&self,
payload: IntoPayload,
) -> PublicationBuilder<&Publisher<'_>, PublicationBuilderPut>
pub fn put<IntoPayload>(&self, payload: IntoPayload) -> PublisherPutBuilder<'_>
where
IntoPayload: Into<Payload>,
{
Expand Down Expand Up @@ -439,7 +448,7 @@ impl<'a> Publisher<'a> {
/// publisher.delete().res().await.unwrap();
/// # }
/// ```
pub fn delete(&self) -> PublicationBuilder<&Publisher<'_>, PublicationBuilderDelete> {
pub fn delete(&self) -> PublisherDeleteBuilder<'_> {
PublicationBuilder {
publisher: self,
kind: PublicationBuilderDelete,
Expand Down
8 changes: 6 additions & 2 deletions zenoh/src/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl Query {
&self,
key_expr: TryIntoKeyExpr,
payload: IntoPayload,
) -> ReplyBuilder<'_, 'b, ReplyBuilderPut>
) -> ReplyPutBuilder<'_, 'b>
where
TryIntoKeyExpr: TryInto<KeyExpr<'b>>,
<TryIntoKeyExpr as TryInto<KeyExpr<'b>>>::Error: Into<zenoh_result::Error>,
Expand Down Expand Up @@ -171,7 +171,7 @@ impl Query {
pub fn reply_del<'b, TryIntoKeyExpr>(
&self,
key_expr: TryIntoKeyExpr,
) -> ReplyBuilder<'_, 'b, ReplyBuilderDelete>
) -> ReplyDeleteBuilder<'_, 'b>
where
TryIntoKeyExpr: TryInto<KeyExpr<'b>>,
<TryIntoKeyExpr as TryInto<KeyExpr<'b>>>::Error: Into<zenoh_result::Error>,
Expand Down Expand Up @@ -274,6 +274,10 @@ pub struct ReplyBuilder<'a, 'b, T> {
attachment: Option<Attachment>,
}

pub type ReplyPutBuilder<'a, 'b> = ReplyBuilder<'a, 'b, ReplyBuilderPut>;

pub type ReplyDeleteBuilder<'a, 'b> = ReplyBuilder<'a, 'b, ReplyBuilderDelete>;

impl<T> TimestampBuilderTrait for ReplyBuilder<'_, '_, T> {
fn timestamp<U: Into<Option<Timestamp>>>(self, timestamp: U) -> Self {
Self {
Expand Down
4 changes: 2 additions & 2 deletions zenoh/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ impl Session {
&'a self,
key_expr: TryIntoKeyExpr,
payload: IntoPayload,
) -> PublicationBuilder<PublisherBuilder<'a, 'b>, PublicationBuilderPut>
) -> SessionPutBuilder<'a, 'b>
where
TryIntoKeyExpr: TryInto<KeyExpr<'b>>,
<TryIntoKeyExpr as TryInto<KeyExpr<'b>>>::Error: Into<zenoh_result::Error>,
Expand Down Expand Up @@ -745,7 +745,7 @@ impl Session {
pub fn delete<'a, 'b: 'a, TryIntoKeyExpr>(
&'a self,
key_expr: TryIntoKeyExpr,
) -> PublicationBuilder<PublisherBuilder<'a, 'b>, PublicationBuilderDelete>
) -> SessionDeleteBuilder<'a, 'b>
where
TryIntoKeyExpr: TryInto<KeyExpr<'b>>,
<TryIntoKeyExpr as TryInto<KeyExpr<'b>>>::Error: Into<zenoh_result::Error>,
Expand Down

0 comments on commit 8f8eb25

Please sign in to comment.