Skip to content

Cannot implement my own Executor #25

Description

@PatatasDelPapa

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\github.com-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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions