New Structs for handling several IO handlers#6
Open
OscarFdezS wants to merge 7 commits into
Open
Conversation
New no_std version
…carFdezS/xdevs_no_std.rs into dev-rt_sim_with_input_handler
romancardenas
requested changes
Aug 13, 2024
Comment on lines
8
to
+10
| /// Closure for RT simulation on targets with `std`. | ||
| /// It sleeps until the next state transition. | ||
| /// It is an implementation of the `wait_until` closure for the `Simulator::simulate_rt` method. |
Collaborator
There was a problem hiding this comment.
Suggested change
| /// Closure for RT simulation on targets with `std`. | |
| /// It sleeps until the next state transition. | |
| /// It is an implementation of the `wait_until` closure for the `Simulator::simulate_rt` method. | |
| /// Closure for RT simulation on targets with `std`. It sleeps until the next state transition. | |
| /// It is an implementation of the `wait_until` closure for the `Simulator::simulate_rt` method. |
|
|
||
| type OutputHandler<T> = Box<dyn FnMut(&T)>; | ||
|
|
||
| /// A struct that represents a multiple output handler. |
Collaborator
There was a problem hiding this comment.
Suggested change
| /// A struct that represents a multiple output handler. | |
| /// A struct that aggregates multiple output handlers. |
| ohs: Vec<OutputHandler<T>>, | ||
| } | ||
|
|
||
| /// A struct representing a multiple output handler for a generic type `T`. |
Collaborator
There was a problem hiding this comment.
Suggested change
| /// A struct representing a multiple output handler for a generic type `T`. |
Comment on lines
+144
to
+145
| /// * `F` - The function type used to inject events into the model. This function is implementaion-specific and it takes a mutable reference to T and event U as input. | ||
| /// * `U` - It is the event type handled by the mpsc channel. It must implement the `Default` trait. |
Collaborator
There was a problem hiding this comment.
Suggested change
| /// * `F` - The function type used to inject events into the model. This function is implementaion-specific and it takes a mutable reference to T and event U as input. | |
| /// * `U` - It is the event type handled by the mpsc channel. It must implement the `Default` trait. | |
| /// * `U` - It is the event type handled by the mpsc channel. It must implement the `Default` trait. | |
| /// * `F` - The function type used to inject events into the model. | |
| /// This function is implementation-specific and it takes a mutable reference to T and event U as input. |
Comment on lines
+146
to
+153
| /// | ||
| /// # Fields | ||
| /// * `phantom` - A phantom data marker to hold the generic type `T`. | ||
| /// * `tx` - The sender side of the mpsc channel used to send events. | ||
| /// * `rx` - The receiver side of the mpsc channel used to receive events. | ||
| /// * `thread_handles` - A vector holding the handles of the spawned threads. | ||
| /// * `window_time` - An optional duration representing the window time for collecting extra events. | ||
| /// * `inject_event` - A function used to inject events into the model. |
Collaborator
There was a problem hiding this comment.
Suggested change
| /// | |
| /// # Fields | |
| /// * `phantom` - A phantom data marker to hold the generic type `T`. | |
| /// * `tx` - The sender side of the mpsc channel used to send events. | |
| /// * `rx` - The receiver side of the mpsc channel used to receive events. | |
| /// * `thread_handles` - A vector holding the handles of the spawned threads. | |
| /// * `window_time` - An optional duration representing the window time for collecting extra events. | |
| /// * `inject_event` - A function used to inject events into the model. |
Comment on lines
+158
to
+163
| phantom: std::marker::PhantomData<T>, | ||
| tx: std::sync::mpsc::Sender<U>, | ||
| rx: std::sync::mpsc::Receiver<U>, | ||
| thread_handles: Vec<std::thread::JoinHandle<()>>, | ||
| window_time: Option<Duration>, | ||
| inject_event: F, |
Collaborator
There was a problem hiding this comment.
Suggested change
| phantom: std::marker::PhantomData<T>, | |
| tx: std::sync::mpsc::Sender<U>, | |
| rx: std::sync::mpsc::Receiver<U>, | |
| thread_handles: Vec<std::thread::JoinHandle<()>>, | |
| window_time: Option<Duration>, | |
| inject_event: F, | |
| _phantom: std::marker::PhantomData<T>, | |
| /// The sender side of the mpsc channel used to send events. | |
| tx: std::sync::mpsc::Sender<U>, | |
| /// The receiver side of the mpsc channel used to receive events. | |
| rx: std::sync::mpsc::Receiver<U>, | |
| /// A vector holding the handles of the spawned threads. | |
| thread_handles: Vec<std::thread::JoinHandle<()>>, | |
| /// An optional duration representing the window time for collecting extra events. | |
| window_time: Option<Duration>, | |
| /// A function used to inject events into the model. | |
| inject_event: F, |
| pub fn new(window_time: Option<Duration>, inject_event: F) -> Self { | ||
| let (tx, rx) = mpsc::channel::<U>(); | ||
| Self { | ||
| phantom: std::marker::PhantomData, |
Collaborator
There was a problem hiding this comment.
Suggested change
| phantom: std::marker::PhantomData, | |
| _phantom: std::marker::PhantomData, |
| } | ||
|
|
||
| /// Internal function to get the event from the receiver within the specified duration | ||
| fn _get_event<U: core::default::Default>(rx: &mpsc::Receiver<U>, d: Duration) -> U { |
Collaborator
There was a problem hiding this comment.
The underscore thing in Rust is for unused stuff (or weird embedded functions).
Suggested change
| fn _get_event<U: core::default::Default>(rx: &mpsc::Receiver<U>, d: Duration) -> U { | |
| fn get_event<U: core::default::Default>(rx: &mpsc::Receiver<U>, d: Duration) -> U { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.