Comments (2)
Macro-based solutions like https://docs.rs/enum_dispatch/latest/enum_dispatch/ or https://sigp.github.io/superstruct/codegen/enum.html might be useful.
On the other hand, my personal proposal in the past (this doesn't make code shorter though, but at least repeating oneself is no longer needed:
variant NewType<T>(T);
use NewType as NT;
#[derive(Clone, PartialEq)]
enum FooBar = NT<Foo> + NT<Bar>;
from rfcs.
Unless you need to pass the nested Foo
or Bar
in its entirety, I found it a bit more elegant to expand the enum variants to contain anonymous struct, then do destructuring when matching, binding what I need then and passing it forward.
from rfcs.
Related Issues (20)
- Better wrapper structs HOT 7
- Remove all panics from standard library HOT 25
- Generate an automatic implementation of TryFrom and Into for C-style enums HOT 5
- Redesign `Arc` API HOT 5
- Float rounding with specified digits HOT 4
- Refactor shared methods of `f32` and `f64` into new `Float` trait HOT 3
- Enable `Self = F` in generic `where` clause HOT 1
- Named opt-in trait impls HOT 2
- Question/proposal: Struct specialization HOT 3
- https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints uses `-` HOT 1
- new type of enum HOT 8
- Pre-RFC: Add a built-in support for totality (or non-panicking/aborting) asserting HOT 6
- Potential Compiler Optimization Issue with &Vec<Vec<T>> vs &[Vec<T>]? HOT 1
- Discussion/Pre-RFC/ACP: Unify privately constructed ("protected") ZSTs in std
- Create a struct similar to std::fs::File for directories HOT 2
- Converging let else HOT 1
- Conditional visibility: for integration testing purpose. HOT 1
- [moved] Redefine `CARGO_TARGET_DIR` to be only an artifacts directory HOT 3
- Allow opting out of specific parts of core crate (e.g. core::fmt) HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rfcs.