From bb7923f689f203726911395db38d00513d349225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ja=C5=ADhien=20Piatlicki?= Date: Mon, 25 Nov 2024 10:17:48 +0100 Subject: [PATCH] Changes after review --- nexosim/examples/uni_requestor.rs | 4 ++-- nexosim/src/ports/output.rs | 18 ++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/nexosim/examples/uni_requestor.rs b/nexosim/examples/uni_requestor.rs index 6c722de..bd24044 100644 --- a/nexosim/examples/uni_requestor.rs +++ b/nexosim/examples/uni_requestor.rs @@ -109,7 +109,7 @@ impl Env { impl Model for Env {} -/// Orbiting Mars and looking for its climate remember to convert units. +/// Converts Fahrenheit to Celsius. pub fn fahr_to_cels(t: f64) -> f64 { 5.0 * (t - 32.0) / 9.0 } @@ -124,7 +124,7 @@ fn main() -> Result<(), SimulationError> { let env_mbox = Mailbox::new(); // Connect data line and convert Fahrenheit degrees to Celsius. - let temp_req = UniRequestor::new_map_connected(|x| *x, fahr_to_cels, Env::get_temp, &env_mbox); + let temp_req = UniRequestor::with_map(|x| *x, fahr_to_cels, Env::get_temp, &env_mbox); // Models. let mut sensor = Sensor::new(100.0, temp_req); diff --git a/nexosim/src/ports/output.rs b/nexosim/src/ports/output.rs index f36fb0f..d1f838b 100644 --- a/nexosim/src/ports/output.rs +++ b/nexosim/src/ports/output.rs @@ -303,23 +303,21 @@ impl fmt::Debug for Requestor { sender: Box>, } impl UniRequestor { - /// Creates new UniRequestor port connected to a replier port of the model + /// Creates a new `UniRequestor` port connected to a replier port of the model /// specified by the address. /// /// 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 context reference. - pub fn new_connected(replier: F, address: impl Into>) -> Self + pub fn new(replier: F, address: impl Into>) -> Self where M: Model, F: for<'a> ReplierFn<'a, M, T, R, S> + Clone, @@ -330,7 +328,7 @@ impl UniRequestor { Self { sender } } - /// Creates new UniRequestor port connected with auto-conversion to a + /// Creates a new `UniRequestor` port connected with auto-conversion to a /// replier port of the model specified by the address. /// /// Queries and replies are mapped to other types using the closures @@ -340,7 +338,7 @@ impl UniRequestor { /// 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 new_map_connected( + pub fn with_map( query_map: C, reply_map: D, replier: F, @@ -365,7 +363,7 @@ impl UniRequestor { Self { sender } } - /// Creates neq UniRequestor port connected with filtering and + /// Creates a new `UniRequestor` port connected with filtering and /// auto-conversion to a replier port of the model specified by the address. /// /// Queries and replies are mapped to other types using the closures @@ -375,7 +373,7 @@ impl UniRequestor { /// 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 new_filter_map_connected( + pub fn with_filter_map( query_filer_map: C, reply_map: D, replier: F, @@ -400,7 +398,7 @@ impl UniRequestor { Self { sender } } - /// Send a query to the connected replier port. + /// Sends a query to the connected replier port. pub async fn send(&mut self, arg: T) -> Option { if let Some(fut) = self.sender.send_owned(arg) { let output = fut.await.unwrap();