Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example for static dispatch with enums to Command pattern #252

Open
simonsan opened this issue Mar 30, 2021 · 1 comment
Open

Add example for static dispatch with enums to Command pattern #252

simonsan opened this issue Mar 30, 2021 · 1 comment
Labels
A-pattern Area: Content about Patterns C-enhancement Category: Enhancements to content
Projects

Comments

@simonsan
Copy link
Collaborator

Enum is a one way to address the delegation (to commands).
I think enums should be added too. I might add it too a bit later. However, there is also a simple trade off between dyn traits and enums. If delegation occurs externally (crates for example), then trait objects would suit better, since we don't know in advance what kind of type a user may come up with. Like in actix. But if we are going to use it in our own application then since we control the enum variants and if add new variants not too frequently, we could use enum.

Originally posted by @fade2black in #247 (comment)

@simonsan simonsan added C-enhancement Category: Enhancements to content A-pattern Area: Content about Patterns labels Mar 30, 2021
@simonsan simonsan added this to ToDo-Patterns in Content Mar 30, 2021
@pickfire
Copy link
Contributor

pickfire commented Mar 31, 2021

Note that actix-web uses HashMap<Any, ...> for data extractor which trades off type safety (it will error out on runtime rather than compile time for the wrong type) for ergonomic, if we want to do something like this that allows users to use any type but with Any type (not sure if there are any other methods) we would want to state the downsides beforehand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-pattern Area: Content about Patterns C-enhancement Category: Enhancements to content
Projects
Content
ToDo-Patterns
Development

No branches or pull requests

2 participants