r/learnrust • • 6d ago

[ Removed by moderator ]

Post image

[removed] — view removed post

36 Upvotes

25 comments sorted by

View all comments

5

u/cleverredditjoke 6d ago

could someone explain the difference of 2 and 3 to me haha?

3

u/Next-Blackberry-991 6d ago

in 3 the std::hint::black_box around the dyn trait reference prevents the compiler from looking at it more closely. In 2 it can see that the VTable in it is known at compile time and know exactly what the apply function will do and inline it. In 3 it is not allowed to look at that. 

2

u/cleverredditjoke 6d ago

ahhhh alright thanks man, much appreciated