Simplify the API bounds

Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
Marcel Müller 2025-11-04 12:50:44 +01:00
parent 9fac3f08a1
commit 44e8280093

View file

@ -11,13 +11,9 @@ use tytix_core::anyhow;
pub type ReplyOf<M> = <M as Message>::Reply;
pub trait AddressExt<MB> {
fn map<M, R, F, U, RF, RU>(self, f: F, r: RF) -> MappedMessage<Self, M, F, U, RF, RU>
fn map<M, F, U, RF, RU>(self, f: F, r: RF) -> MappedMessage<Self, M, F, U, RF, RU>
where
M: Message,
R: Message + IsContainedInBundle<MB>,
F: FnMut(M) -> U + 'static,
U: Future<Output = R>,
RF: FnMut(<R as Message>::Reply) -> RU + 'static,
MappedMessage<Self, M, F, U, RF, RU>: InternalMessageHandler,
Self: Sized;
fn inspect<F, M, U>(self, f: F) -> Inspect<Self, F, U, M>
@ -28,20 +24,11 @@ pub trait AddressExt<MB> {
}
impl<MB: MessageBundle, A: InternalMessageHandler<HandledMessages = MB>> AddressExt<MB> for A {
fn map<M, R, F, U, RF, RU>(self, f: F, r: RF) -> MappedMessage<Self, M, F, U, RF, RU>
fn map<M, F, U, RF, RU>(self, f: F, r: RF) -> MappedMessage<Self, M, F, U, RF, RU>
where
M: Message,
R: Message + IsContainedInBundle<MB>,
F: FnMut(M) -> U + 'static,
RF: FnMut(<R as Message>::Reply) -> RU + 'static,
MappedMessage<Self, M, F, U, RF, RU>: InternalMessageHandler,
Self: Sized,
{
const {
let true = <R as IsContainedInBundle<MB>>::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<Output = anyhow::Result<InternalMessage>> {
drop(msg);
async { Ok(InternalMessage::new(())) }
) -> anyhow::Result<InternalMessage> {
if let Ok(_foo) = msg.into_inner::<Foo>() {
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!");
}