From 3527d62b41605c200a1cc2f5ab472f02c123eb02 Mon Sep 17 00:00:00 2001 From: Serge Barral Date: Sat, 3 Aug 2024 13:09:36 +0200 Subject: [PATCH] Remove unnecessary trait bounds + improve doc --- asynchronix/src/ports/output.rs | 12 +- asynchronix/src/ports/output/sender.rs | 161 ++++++++----------------- 2 files changed, 53 insertions(+), 120 deletions(-) diff --git a/asynchronix/src/ports/output.rs b/asynchronix/src/ports/output.rs index c98d60f..95d982b 100644 --- a/asynchronix/src/ports/output.rs +++ b/asynchronix/src/ports/output.rs @@ -68,7 +68,7 @@ impl Output { /// /// The input port must be an asynchronous method of a model of type `M` /// taking as argument a value of the type returned by the mapping - /// closure plus, optionally, a scheduler reference. + /// closure plus, optionally, a context reference. pub fn map_connect( &mut self, map: C, @@ -110,7 +110,7 @@ impl Output { /// /// The input port must be an asynchronous method of a model of type `M` /// taking as argument a value of the type returned by the mapping - /// closure plus, optionally, a scheduler reference. + /// closure plus, optionally, a context reference. pub fn filter_map_connect( &mut self, filter_map: C, @@ -216,7 +216,7 @@ impl Requestor { /// /// The replier port must be an asynchronous method of a model of type `M` /// returning a value of type `R` and taking as argument a value of type `T` - /// plus, optionally, a scheduler reference. + /// plus, optionally, a context reference. pub fn connect(&mut self, replier: F, address: impl Into>) -> LineId where M: Model, @@ -234,9 +234,9 @@ impl Requestor { /// provided in argument. /// /// The replier port must be an asynchronous method of a model of type `M` - /// returning a value of the type returned by the second mapping closure and - /// taking as argument a value of the type returned by the first mapping - /// closure plus, optionally, a scheduler reference. + /// returning a value of the type returned by the reply mapping closure and + /// taking as argument a value of the type returned by the query mapping + /// closure plus, optionally, a context reference. pub fn map_connect( &mut self, query_map: C, diff --git a/asynchronix/src/ports/output/sender.rs b/asynchronix/src/ports/output/sender.rs index 66b45e5..5b285cc 100644 --- a/asynchronix/src/ports/output/sender.rs +++ b/asynchronix/src/ports/output/sender.rs @@ -24,11 +24,9 @@ pub(super) trait Sender: DynClone + Send { dyn_clone::clone_trait_object!( Sender); /// An object that can send events to an input port. -pub(super) struct InputSender +pub(super) struct InputSender where - M: Model, - F: for<'a> InputFn<'a, M, T, S>, - T: Send + 'static, + M: 'static, { func: F, sender: channel::Sender, @@ -37,11 +35,9 @@ where _phantom_closure_marker: PhantomData, } -impl InputSender +impl InputSender where - M: Model, - F: for<'a> InputFn<'a, M, T, S>, - T: Send + 'static, + M: 'static, { pub(super) fn new(func: F, sender: channel::Sender) -> Self { Self { @@ -54,12 +50,12 @@ where } } -impl Sender for InputSender +impl Sender for InputSender where M: Model, F: for<'a> InputFn<'a, M, T, S> + Clone, T: Send + 'static, - S: Send + 'static, + S: Send, { fn send(&mut self, arg: T) -> RecycledFuture<'_, Result<(), SendError>> { let func = self.func.clone(); @@ -76,12 +72,10 @@ where } } -impl Clone for InputSender +impl Clone for InputSender where - M: Model, - F: for<'a> InputFn<'a, M, T, S> + Clone, - T: Send + 'static, - S: Send + 'static, + M: 'static, + F: Clone, { fn clone(&self) -> Self { Self { @@ -95,13 +89,9 @@ where } /// An object that can send mapped events to an input port. -pub(super) struct MapInputSender +pub(super) struct MapInputSender where - M: Model, - C: Fn(T) -> U, - F: for<'a> InputFn<'a, M, U, S>, - T: Send + 'static, - U: Send + 'static, + M: 'static, { map: Arc, func: F, @@ -112,13 +102,9 @@ where _phantom_closure_marker: PhantomData, } -impl MapInputSender +impl MapInputSender where - M: Model, - C: Fn(T) -> U, - F: for<'a> InputFn<'a, M, U, S>, - T: Send + 'static, - U: Send + 'static, + M: 'static, { pub(super) fn new(map: C, func: F, sender: channel::Sender) -> Self { Self { @@ -133,14 +119,14 @@ where } } -impl Sender for MapInputSender +impl Sender for MapInputSender where M: Model, C: Fn(T) -> U + Send + Sync, F: for<'a> InputFn<'a, M, U, S> + Clone, T: Send + 'static, U: Send + 'static, - S: Send + 'static, + S: Send, { fn send(&mut self, arg: T) -> RecycledFuture<'_, Result<(), SendError>> { let func = self.func.clone(); @@ -158,14 +144,10 @@ where } } -impl Clone for MapInputSender +impl Clone for MapInputSender where - M: Model, - C: Fn(T) -> U, - F: for<'a> InputFn<'a, M, U, S> + Clone, - T: Send + 'static, - U: Send + 'static, - S: Send + 'static, + M: 'static, + F: Clone, { fn clone(&self) -> Self { Self { @@ -181,30 +163,22 @@ where } /// An object that can filter and send mapped events to an input port. -pub(super) struct FilterMapInputSender +pub(super) struct FilterMapInputSender where - M: Model, - C: Fn(T) -> Option, - F: for<'a> InputFn<'a, M, U, S>, - T: Send + 'static, - U: Send + 'static, + M: 'static, { filter_map: Arc, func: F, sender: channel::Sender, fut_storage: Option>, - _phantom_map: PhantomData U>, + _phantom_filter_map: PhantomData Option>, _phantom_closure: PhantomData, _phantom_closure_marker: PhantomData, } -impl FilterMapInputSender +impl FilterMapInputSender where - M: Model, - C: Fn(T) -> Option, - F: for<'a> InputFn<'a, M, U, S>, - T: Send + 'static, - U: Send + 'static, + M: 'static, { pub(super) fn new(filter_map: C, func: F, sender: channel::Sender) -> Self { Self { @@ -212,21 +186,21 @@ where func, sender, fut_storage: None, - _phantom_map: PhantomData, + _phantom_filter_map: PhantomData, _phantom_closure: PhantomData, _phantom_closure_marker: PhantomData, } } } -impl Sender for FilterMapInputSender +impl Sender for FilterMapInputSender where M: Model, C: Fn(T) -> Option + Send + Sync, F: for<'a> InputFn<'a, M, U, S> + Clone, T: Send + 'static, U: Send + 'static, - S: Send + 'static, + S: Send, { fn send(&mut self, arg: T) -> RecycledFuture<'_, Result<(), SendError>> { let func = self.func.clone(); @@ -248,14 +222,10 @@ where } } -impl Clone for FilterMapInputSender +impl Clone for FilterMapInputSender where - M: Model, - C: Fn(T) -> Option, - F: for<'a> InputFn<'a, M, U, S> + Clone, - T: Send + 'static, - U: Send + 'static, - S: Send + 'static, + M: 'static, + F: Clone, { fn clone(&self) -> Self { Self { @@ -263,7 +233,7 @@ where func: self.func.clone(), sender: self.sender.clone(), fut_storage: None, - _phantom_map: PhantomData, + _phantom_filter_map: PhantomData, _phantom_closure: PhantomData, _phantom_closure_marker: PhantomData, } @@ -271,17 +241,13 @@ where } /// An object that can send an event to an event sink. -pub(super) struct EventSinkSender> -where - T: Send + 'static, - W: EventSinkWriter, -{ +pub(super) struct EventSinkSender { writer: W, fut_storage: Option>, _phantom_event: PhantomData, } -impl> EventSinkSender { +impl EventSinkSender { pub(super) fn new(writer: W) -> Self { Self { writer, @@ -307,11 +273,7 @@ where } } -impl Clone for EventSinkSender -where - T: Send + 'static, - W: EventSinkWriter, -{ +impl Clone for EventSinkSender { fn clone(&self) -> Self { Self { writer: self.writer.clone(), @@ -324,10 +286,7 @@ where /// An object that can send mapped events to an event sink. pub(super) struct MapEventSinkSender where - T: Send + 'static, - U: Send + 'static, C: Fn(T) -> U, - W: EventSinkWriter, { writer: W, map: Arc, @@ -337,10 +296,7 @@ where impl MapEventSinkSender where - T: Send + 'static, - U: Send + 'static, C: Fn(T) -> U, - W: EventSinkWriter, { pub(super) fn new(map: C, writer: W) -> Self { Self { @@ -373,10 +329,8 @@ where impl Clone for MapEventSinkSender where - T: Send + 'static, - U: Send + 'static, - C: Fn(T) -> U + Send + Sync, - W: EventSinkWriter, + C: Fn(T) -> U, + W: Clone, { fn clone(&self) -> Self { Self { @@ -391,10 +345,7 @@ where /// An object that can filter and send mapped events to an event sink. pub(super) struct FilterMapEventSinkSender where - T: Send + 'static, - U: Send + 'static, C: Fn(T) -> Option, - W: EventSinkWriter, { writer: W, filter_map: Arc, @@ -404,10 +355,7 @@ where impl FilterMapEventSinkSender where - T: Send + 'static, - U: Send + 'static, C: Fn(T) -> Option, - W: EventSinkWriter, { pub(super) fn new(filter_map: C, writer: W) -> Self { Self { @@ -442,10 +390,8 @@ where impl Clone for FilterMapEventSinkSender where - T: Send + 'static, - U: Send + 'static, - C: Fn(T) -> Option + Send + Sync, - W: EventSinkWriter, + C: Fn(T) -> Option, + W: Clone, { fn clone(&self) -> Self { Self { @@ -458,7 +404,10 @@ where } /// An object that can send requests to a replier port and retrieve responses. -pub(super) struct ReplierSender { +pub(super) struct ReplierSender +where + M: Model, +{ func: F, sender: channel::Sender, receiver: multishot::Receiver, @@ -470,9 +419,6 @@ pub(super) struct ReplierSender { impl ReplierSender where M: Model, - F: for<'a> ReplierFn<'a, M, T, R, S>, - T: Send + 'static, - R: Send + 'static, { pub(super) fn new(func: F, sender: channel::Sender) -> Self { Self { @@ -528,10 +474,7 @@ where impl Clone for ReplierSender where M: Model, - F: for<'a> ReplierFn<'a, M, T, R, S> + Clone, - T: Send + 'static, - R: Send + 'static, - S: Send, + F: Clone, { fn clone(&self) -> Self { Self { @@ -547,7 +490,10 @@ where /// An object that can send mapped requests to a replier port and retrieve /// mapped responses. -pub(super) struct MapReplierSender { +pub(super) struct MapReplierSender +where + M: Model, +{ query_map: Arc, reply_map: Arc, func: F, @@ -563,13 +509,6 @@ pub(super) struct MapReplierSender { impl MapReplierSender where M: Model, - C: Fn(T) -> U, - D: Fn(Q) -> R, - F: for<'a> ReplierFn<'a, M, U, Q, S>, - T: Send + 'static, - R: Send + 'static, - U: Send + 'static, - Q: Send + 'static, { pub(super) fn new(query_map: C, reply_map: D, func: F, sender: channel::Sender) -> Self { Self { @@ -639,13 +578,7 @@ where impl Clone for MapReplierSender where M: Model, - C: Fn(T) -> U, - D: Fn(Q) -> R, - F: for<'a> ReplierFn<'a, M, U, Q, S> + Clone, - T: Send + 'static, - R: Send + 'static, - U: Send + 'static, - Q: Send + 'static, + F: Clone, { fn clone(&self) -> Self { Self {