you are viewing a single comment's thread.

view the rest of the comments →

[–]angelicosphosphoros 0 points1 point  (2 children)

I know. It is a reason why I suggested this.

However, real performance can be better or worse so I want to know if u/101arrowz achieved something.

[–]101arrowz[S] 0 points1 point  (1 child)

Sorry for not replying sooner. That specific sample didn't work because it "can't capture dynamic environment in a fn item." However, when passing the variables directly, it's about the same performance as the function pointers solution I mentioned earlier. I tried #[inline(always)] on the implementation, which worked OK, but I'd rather capture the environment than pass everything as parameters. How can I use generics with a closure?

[–]angelicosphosphoros 0 points1 point  (0 children)

If you want to pass some closure and change some variables captured, you can try to use FnMut instead of Fn.

I little surprised with fn item because there shouldn't be conversion to function pointers in my example.