rust-unofficial / patterns

A catalogue of Rust design patterns, anti-patterns and idioms
https://rust-unofficial.github.io/patterns/
Mozilla Public License 2.0
7.98k stars 363 forks source link

New idiom: Out of the Box Dynamic Dispatch #94

Closed llogiq closed 4 years ago

twe4ked commented 4 years ago

Great write up! I was a bit confused by the title at first, perhaps something along the lines of “Dynamic Dispatch without Box”?

llogiq commented 4 years ago

Perhaps on-stack dynamic dispatch?

twe4ked commented 4 years ago

That sounds good to me ☺️

llogiq commented 4 years ago

It's been a while since there was any movement on this. Is there something I should do or is this good to merge?

llogiq commented 4 years ago

@lambda-fairy @Manishearth anyone?

lambda-fairy commented 4 years ago

Hey @llogiq!

Sorry, I've had way too many things going on lately 😢

It looks like the document is still called ootb-dyn-dispatch.md. Can you please rename that to something like on-stack-dyn-dispatch.md?

Otherwise it looks good to me 👍

burdges commented 4 years ago

I suppose LLVM always eliminates the duplicate stack usage here, so there is never a reason to do this with a union.

pickfire commented 4 years ago

@llogiq I think you could also add an example for Option. I saw it somewhere in some blog posts.

llogiq commented 4 years ago

@pickfire I've noted in the "see also" section that Option.as_ref() solves most of the same problem for us.

llogiq commented 4 years ago

Moved the file and rebased. @lambda-fairy r?