Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot implement my own Executor #25

Open
PatatasDelPapa opened this issue Aug 29, 2022 · 1 comment
Open

Cannot implement my own Executor #25

PatatasDelPapa opened this issue Aug 29, 2022 · 1 comment
Assignees

Comments

@PatatasDelPapa
Copy link

PatatasDelPapa commented Aug 29, 2022

I followed the code of execute_until for my onw Executor to this adaptation and it will not compile

struct MyExecutor {
    limit: Duration
};

impl Execute for MyExecutor {
    fn execute(self, sim: &mut Simulation) {
        while sim.scheduler.peek().map_or(false, |e| e.time() < self.limit) {
            sim.step();
        }
    }
}

it produces the following error

error[E0624]: associated function `time` is private
  --> src/lib.rs:14:56
   |
14 |         while sim.scheduler.peek().map_or(false, |e| e.time() < self.limit) {
   |                                                        ^^^^ private associated function
   |
  ::: C:\Users\patatas\.cargo\registry\src\jackfan.us.kg-1ecc6299db9ec823\simrs-0.2.0\src\scheduler.rs:55:5
   |
55 |     pub(crate) fn time(&self) -> Duration {
   |     ------------------------------------- private associated function defined here

For more information about this error, try `rustc --explain E0624`.

For context I'm comparing models between some simulation libraries one of those libraries only let's you define a limit and it will stop if the simulation time is >= to the limit imposed. The Executor provided instead will continue the simulation until time > limit

For context I'm comparing models between simulation libraries, one of those libraries let's you define a limit in term of seconds and it will stop the simulation if time >= limit meanwhile the Executor provided will execute the simulation while e.time() <= time remains true (from the execute_until code) this causes that the same model can produce different results because in one library it will execute less events than the other (that does happens to me) so I decided to implement my own executor by implementing Execute following a simplified version of the one in the library sadly it doesn't compile because it tried to access a private method.

This is not grave to me because this can be adapted to

let clock = simulation.scheduler.clock();
while simulation.scheduler.peek().is_some() && clock.time() < limit {
    simulation.step();
}

but ideally the version using Execute should compile.
EDIT: I just realized I could just do the above in the Executor too... Well that's why I get for trying to copy the source code :D

@elshize elshize self-assigned this Sep 7, 2022
@elshize
Copy link
Owner

elshize commented Sep 7, 2022

Thanks for submitting this @PatatasDelPapa Glad you found a workaround. It's true that making the method public would fix the compilation, but I'm not entirely sure I want that. I need to revisit this carefully before making the decision.

The thing is that this event type is a piece of internal machinery, and I'd like to close as much of it as possible. It might be better to, say, add a next_time method to the scheduler for example, that would return an optional.

In fact, I'd love to make EventEntry totally hidden from the user, but I'm not sure that's possible... Need to experiment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants