Skip to content

Allow borrowing an Enum variant as a plain tuple (Feat. Req.) #7407

Closed
@bluss

Description

@bluss

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.

enum Pair<A,B> {
  Nothing,
  Two(A, B),
}

let p: Pair<A, B>;
match p {
   Two(a, b) => (a, b).iter_bytes()
}

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions