evenfurther / pathfinding

Pathfinding library for rust
856 stars 71 forks source link

Usage of FnMut in `astar` #252

Closed felix91gr closed 4 years ago

felix91gr commented 4 years ago

Hi @samueltardieu, long time no see ^^ I hope the global situation is treating you as well as it can. :heart:

I was taking a peek at the docs once again, and the fact that FnMut is used in astar grabbed my attention. Why is it that successors, heuristic and success have to be FnMut? Couldn't they be just Fn?

Thanks in advance :)

issue-label-bot[bot] commented 4 years ago

Issue Label Bot is not confident enough to auto-label this issue. See dashboard for more details.

samueltardieu commented 4 years ago

Hi @felix91gr !

They are FnMut because you might want to keep a state. For example, you might want to limit the search to a given number of steps, in which case you would make such a test in successors or success. You might also want to tweak heuristic in order to influence the search less and less as it advances if it has not proven to be successful so far.

I hope this answers your question.

felix91gr commented 4 years ago

@samueltardieu I see, that makes a lot of sense!

And well, since Fn : FnMut, I guess if one wanted to limit the input functions to be read-only, there is the option to do so, with a wrapper function over astar that received Fn types instead of FnMut. That's actually super nice :)

Thank you, and take care :slightly_smiling_face: