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

Expand Constant to allow getting its Type #279

Open
eugenesvk opened this issue Oct 6, 2023 · 2 comments
Open

Expand Constant to allow getting its Type #279

eugenesvk opened this issue Oct 6, 2023 · 2 comments

Comments

@eugenesvk
Copy link
Contributor

eugenesvk commented Oct 6, 2023

I'd like to get a list of all of crate's constants with their type and values, the latest changes allowed getting the values, but still not Type.

There is a workaround you suggested using Constant ID to find the required information, but it'd be nicer to be able to use the query language for that

You mentioned that this is pending Trustfall support for types

Once Trustfall supports custom scalar types, it gives us the option of adding a "proper" type_ field to the schema that will be more ergonomic.

@obi1kenobi
Copy link
Owner

Thanks for the issue and for the PR.

as far as I understood, this is the ultimate crate that enables that

Thanks, it certainly tries to 😄 If you don't mind sharing, I'm curious to hear more! How did you come across this crate? What's the use case you are targeting?

@eugenesvk
Copy link
Contributor Author

tldr: I wanted to parse Windows_sys crate for its constants (names/values), started with a cargo-semver-checks crate and after some digging through sparse docs and code realized that this adapter is the one providing all the schema descriptions

A bit more context: I wanted to have a more ergonomic way to use Windows constants to call Windows APIs in a scripting language:

  • 4097 instead of some unreadable value that you have to lookup somewhere
  • LOCALE_SENGLANGUAGE you could just copy&paste the full name from the API MS documentation
  • sEngLng or even better use a more readable shorter name

Given that there are >100k constants, I couldn't load them dynamically within the language itself, so I thought I'd write a Rust library that stores all the values and returns them from a constant name. Found the Windows_sys crate that has all the contants, realized there is no reflection in Rust (so I can't just compile the crate and ask it to list all the contants), but someone at the Rust language forums suggested to look at cargo-semver-checks which parses cargo docs that contains that information.

So I've looked at the pub_module_level_const_missing.ron query, realized it's also missing :( the info, digged into what the semver checks is doing and ended up at this adapter crate

@eugenesvk eugenesvk changed the title Expand Constant to allow getting its type/value/expr/literal status Expand Constant to allow getting its Type Oct 9, 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

2 participants