From 44e82800937e2ddbed98d9ff51e1a34bd7509565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Tue, 4 Nov 2025 12:50:44 +0100 Subject: [PATCH] Simplify the API bounds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcel Müller --- crates/tytix/src/lib.rs | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/crates/tytix/src/lib.rs b/crates/tytix/src/lib.rs index 6708a77..ca900dc 100644 --- a/crates/tytix/src/lib.rs +++ b/crates/tytix/src/lib.rs @@ -11,13 +11,9 @@ use tytix_core::anyhow; pub type ReplyOf = ::Reply; pub trait AddressExt { - fn map(self, f: F, r: RF) -> MappedMessage + fn map(self, f: F, r: RF) -> MappedMessage where - M: Message, - R: Message + IsContainedInBundle, - F: FnMut(M) -> U + 'static, - U: Future, - RF: FnMut(::Reply) -> RU + 'static, + MappedMessage: InternalMessageHandler, Self: Sized; fn inspect(self, f: F) -> Inspect @@ -28,20 +24,11 @@ pub trait AddressExt { } impl> AddressExt for A { - fn map(self, f: F, r: RF) -> MappedMessage + fn map(self, f: F, r: RF) -> MappedMessage where - M: Message, - R: Message + IsContainedInBundle, - F: FnMut(M) -> U + 'static, - RF: FnMut(::Reply) -> RU + 'static, + MappedMessage: InternalMessageHandler, Self: Sized, { - const { - let true = >::IS_CONTAINED else { - panic!("Message is not contained in MessageBundle",); - }; - } - MappedMessage { address: self, func: f, @@ -166,7 +153,7 @@ mod tests { struct Foo; impl Message for Foo { - type Reply = (); + type Reply = usize; } struct Bar; @@ -180,13 +167,15 @@ mod tests { impl InternalMessageHandler for SimpleAddress { type HandledMessages = (Foo, Bar); - fn handle_message( + async fn handle_message( &mut self, msg: tytix_core::InternalMessage, - ) -> impl Future> { - drop(msg); - - async { Ok(InternalMessage::new(())) } + ) -> anyhow::Result { + if let Ok(_foo) = msg.into_inner::() { + Ok(InternalMessage::new(42usize)) + } else { + Ok(InternalMessage::new(())) + } } } @@ -202,7 +191,7 @@ mod tests { |_a| async {}, ); - sa.send(Bar).await.unwrap(); + let () = sa.send(Bar).await.unwrap(); MSG.get().expect("The message was mapped!"); }