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

Allow "matchers" for types such that cases can be labeled with identifiers rather than integers #2

Open
sdleffler opened this issue Apr 23, 2021 · 0 comments

Comments

@sdleffler
Copy link

Currently, the integer identifiers used for indexing cases in the case! macro correspond to type parameters passed to the Case<const N: usize> trait. This makes it a bit inconvenient to name the case identifiers with anything other than usize literals. But there is a way we can get around this, by generating macros that convert identifiers into usize tokens:

mod Option {
    #[macro_export]
    macro_rules! Option_matcher {
        (Some) => { 0 };
        (None) => { 1 };
    }
}

Unfortunately there's a large snag with this approach; macros in "path-based" scope will ALWAYS live in the crate root where they are defined. As a result, punning modules and types and getting the kind of scope punning we want does not work. Some kind of bespoke name mangling inside the case! macro might work; or, we might have to make the concept of "matcher" or "case address"/"indexing" macros more first-class.

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