Skip to content

Commit

Permalink
Use GATs to make SessionExt work better with Arc<Session> (#584)
Browse files Browse the repository at this point in the history
Co-authored-by: Pierre Avital <[email protected]>
  • Loading branch information
p-avital and Pierre Avital authored Nov 10, 2023
1 parent 643d767 commit 7b51d04
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion zenoh-ext/src/session_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ use zenoh::{Session, SessionRef};

/// Some extensions to the [`zenoh::Session`](zenoh::Session)
pub trait SessionExt {
type PublicationCacheBuilder<'a, 'b, 'c>
where
Self: 'a;
fn declare_publication_cache<'a, 'b, 'c, TryIntoKeyExpr>(
&'a self,
pub_key_expr: TryIntoKeyExpr,
) -> PublicationCacheBuilder<'a, 'b, 'c>
) -> Self::PublicationCacheBuilder<'a, 'b, 'c>
where
TryIntoKeyExpr: TryInto<KeyExpr<'b>>,
<TryIntoKeyExpr as TryInto<KeyExpr<'b>>>::Error: Into<zenoh_result::Error>;
}

impl SessionExt for Session {
type PublicationCacheBuilder<'a, 'b, 'c> = PublicationCacheBuilder<'a, 'b, 'c>;
fn declare_publication_cache<'a, 'b, 'c, TryIntoKeyExpr>(
&'a self,
pub_key_expr: TryIntoKeyExpr,
Expand All @@ -44,6 +48,20 @@ impl SessionExt for Session {
}
}

impl<T: ArcSessionExt + 'static> SessionExt for T {
type PublicationCacheBuilder<'a, 'b, 'c> = PublicationCacheBuilder<'static, 'b, 'c>;
fn declare_publication_cache<'a, 'b, 'c, TryIntoKeyExpr>(
&'a self,
pub_key_expr: TryIntoKeyExpr,
) -> Self::PublicationCacheBuilder<'a, 'b, 'c>
where
TryIntoKeyExpr: TryInto<KeyExpr<'b>>,
<TryIntoKeyExpr as TryInto<KeyExpr<'b>>>::Error: Into<zenoh_result::Error>,
{
ArcSessionExt::declare_publication_cache(self, pub_key_expr)
}
}

pub trait ArcSessionExt {
fn declare_publication_cache<'b, 'c, TryIntoKeyExpr>(
&self,
Expand Down

0 comments on commit 7b51d04

Please sign in to comment.