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

Support ignore, using for enums? #37

Open
dhardy opened this issue Sep 7, 2023 · 0 comments
Open

Support ignore, using for enums? #37

dhardy opened this issue Sep 7, 2023 · 0 comments

Comments

@dhardy
Copy link
Contributor

dhardy commented Sep 7, 2023

#31 mostly implemented #6 (support enums), but with a significant missing feature: lack of support for using and ignore keywords.

The reason is very simple: syntax.

Case study: ignore

I recently wanted to implement Debug on the following enum. The problem: kas::Window does not support Debug. This was not important for my debugging purposes, but prevented use of derive or autoimpl.

enum PendingAction<A: crate::AppData> {
    AddPopup(WindowId, WindowId, kas::PopupDescriptor),
    AddWindow(WindowId, kas::Window<A>),
    CloseWindow(WindowId),
    Action(kas::Action),
}

This enum's variants use tuple syntax, but ignore self.1 is not specific enough.

This is sufficient: ignore AddWindow::1. It is not correct Rust syntax since AddWindow is not a type (though there was a proposal in that direction) and ::1 is not a valid path element (tuples not needing this).

Alternatively: AddWindow.1. This is also not correct Rust syntax since AddWindow is not a value, but at least .1 is a valid field accessor, so this may be the better option.

Using multiple fields?

Unlike ignore, using normally only targets a single field. Implementing e.g. Deref on an enum would require a field for each variant. This should not be a problem, however:

#[autoimpl(Deref<Target = T> using A.0, B.0)]
enum Either<T> {
    A(T),
    B(T),
}

Summary

The above, using . field accessors, appears a reasonable proposition, despite not being true Rust syntax.

There is motivation for supporting at least ignore on enums, though given how long it took me to find a real example this appears limited.

I will leave this issue open for now. Comments welcome.

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

1 participant