-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Allow borrowing an Enum variant as a plain tuple (Feat. Req.) #7407
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
Comments
Can you use |
jdm, no. For the purposes of this example, Pair does not implement the trait we want to use. IterBytes is a convenient example because that trait exists in std. Of course for this particular trait we have an alternative -> deriving, but I think the tuple borrow would be generally useful. |
I'm not sure what you're asking here, if it's to allow something like the pattern If you're asking to treat I'm going to close this as I cannot think of a realistic use case where you wouldn't just use a tuple anyway. |
it's not about pattern matching, but allowing to borrow a variant as a pointer to a similar tuple type. It could be a function. |
Don't suggest doc(hidden) or unstable variants in wildcard lint Clippy's wildcard lint would suggest doc(hidden) and unstable variants for non_exhaustive enums, even though those aren't part of the public interface (yet) and should only be matched on using a `_`, just like potential future additions to the enum. There was already some logic to exclude a *single* doc(hidden) variant. This extends that to all hidden variants, and also hides `#[unstable]` variants. See rust-lang#85746 (comment) This PR includes rust-lang/rust-clippy#7406 as the first commit. Here's the diff that this PR adds on top of that PR: m-ou-se/fork@std-errorkind...m-ou-se:doc-hidden-variants --- *Please write a short comment explaining your change (or "none" for internal only changes)* changelog: No longer suggest unstable and doc(hidden) variants in wildcard lint. wildcard_enum_match_arm, match_wildcard_for_single_variants
Allow borrowing an enum variant as a tuple of the same types, so that you can use methods already defined on a tuple with those types.
This would allow dispatching methods without cloning the Enum variant.
Dispatching tuple methods allow enum impls to re-use functions that are already generically defined over tuples for all type combinations (for example IterBytes).
In a way, it's a simple way to manually do the work of the deriving directive, by reusing the tuple implementation.
The text was updated successfully, but these errors were encountered: