which I call like this: Self::is_complete_move_to(fabric, a).unwrap_or(true).
I think the function should just return bool directly as I always want failure / None to mean that the action is completed (=true). Later I might introduce an enum for running/success/failure but for now I just want to know if the action terminated so that my actor does not get stuck.
I am struggeling to refactor this into a single function considering the potentially failing helper functions fabric.get and Self::entity_target_distance. Any advice how to do this better?
Thanks this looks already much better! It is not equivalent though.. If is_unreachable is false then I need to execute the entity_target_distance check.
I have a bunch of code like this which calls functions which may fail (return Option) because an actor might not have certain properties (or recently lost them). I like ? because it lets me write code as if nothing would fail and then deal with the failure case once at the end.
But I guess ? only works with functions, and not with local scopes, or? So something like is not possible in Rust?
Making ? work in local scopes is the purpose of the unstable try_blocks feature, which adds a try { ... } block that catches any errors from ? expressions. There are a few different technicalities that have caused it to be delayed for quite a while; a catch { ... } block was originally proposed at the same time as the ? operator in 2014.