Skip to content

Allow generic arguments in enum variants - #4

Open
AlephAlpha wants to merge 1 commit into
NyxCode:masterfrom
AlephAlpha:master
Open

Allow generic arguments in enum variants#4
AlephAlpha wants to merge 1 commit into
NyxCode:masterfrom
AlephAlpha:master

Conversation

@AlephAlpha

@AlephAlphaAlephAlpha commented Jun 6, 2021

Copy link
Copy Markdown

Allow generic arguments in enum variants, for example:

#[proxy_enum::proxy(Animal)]mod proxy {usesuper::{Cat,Foo,Lion,Mouse};enumAnimal{Cat(Cat<Foo>),Lion(Lion),Mouse(Mouse),}implAnimal{#[implement]fnfeed(&self){}}}

This would expand to:

mod proxy {usesuper::{Cat,Foo,Lion,Mouse};enumAnimal{Cat(Cat<Foo>),Lion(Lion),Mouse(Mouse),}implAnimal{fnfeed(&self){matchself{Self::Cat(__self) => <Cat<Foo>>::feed(__self),Self::Lion(__self) => <Lion>::feed(__self),Self::Mouse(__self) => <Mouse>::feed(__self),}}}implFrom<Cat<Foo>>forAnimal{fnfrom(from:Cat<Foo>) -> Self{Animal::Cat(from)}}implFrom<Lion>forAnimal{fnfrom(from:Lion) -> Self{Animal::Lion(from)}}implFrom<Mouse>forAnimal{fnfrom(from:Mouse) -> Self{Animal::Mouse(from)}}}

The < and > around the type are only added for inherent implementations, not trait implementations.

@AlephAlpha

Copy link
Copy Markdown
Author

Sorry for my username. It's just a coincidence.

@AlephAlphaAlephAlpha changed the title Allow generic parameters in enum variantsAllow generic arguments in enum variantsJun 6, 2021
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@AlephAlpha