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

we can combine struct and enum #119320

Closed
ikaasraa opened this issue Dec 26, 2023 · 3 comments
Closed

we can combine struct and enum #119320

ikaasraa opened this issue Dec 26, 2023 · 3 comments

Comments

@ikaasraa
Copy link

ikaasraa commented Dec 26, 2023

hello ... I love ....
I am new and beginner rust developer when I learn enum and struct I think we can combine struct and enum to just struct and delete enum for ever and just have struct...

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 26, 2023
@fmease
Copy link
Member

fmease commented Dec 26, 2023

Structs and enums are related but still conceptually distinct features. I would recommend reading up on Chapter 5: Structs and Chapter 6: Enum of the book.
It's true that type-theoretically structs are 1-variant enums (however, it would be very unwise to get rid of enums in favor of structs as you have suggested). So the following struct

struct S { f: T }

can be represented via

enum E { S { f: T } }

Except that in Rust, you would now need to use pattern matching to access the field f (which is now public btw) which is not as ergonomic meaning structs have reason to be in the language as a separate kind of item.

@fmease
Copy link
Member

fmease commented Dec 26, 2023

In the future, please consider opening a thread over at https://internals.rust-lang.org/ or https://rust-lang.zulipchat.com/ first for questions about language design and/or language proposals.

I also recommend you to try out support forums like Discord first. This issue tracker is mostly for bugs found in the Rust compiler.

@fmease
Copy link
Member

fmease commented Dec 26, 2023

Closing as invalid.

@fmease fmease closed this as not planned Won't fix, can't repro, duplicate, stale Dec 26, 2023
@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants