From c177cc99a7044662d5b6d0fcaddff31da04e2c61 Mon Sep 17 00:00:00 2001 From: Pierre Avital Date: Fri, 10 Nov 2023 15:02:21 +0100 Subject: [PATCH] use GATs to make SessionExt work better with Arc --- zenoh-ext/src/session_ext.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/zenoh-ext/src/session_ext.rs b/zenoh-ext/src/session_ext.rs index 3ffd328e1a..3f9a428293 100644 --- a/zenoh-ext/src/session_ext.rs +++ b/zenoh-ext/src/session_ext.rs @@ -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>, >>::Error: Into; } 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, @@ -44,6 +48,20 @@ impl SessionExt for Session { } } +impl 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>, + >>::Error: Into, + { + ArcSessionExt::declare_publication_cache(self, pub_key_expr) + } +} + pub trait ArcSessionExt { fn declare_publication_cache<'b, 'c, TryIntoKeyExpr>( &self,