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

const fn getters #41

Open
Apanatshka opened this issue Apr 9, 2024 · 2 comments
Open

const fn getters #41

Apanatshka opened this issue Apr 9, 2024 · 2 comments

Comments

@Apanatshka
Copy link

I'm using bitfield combined with varlen, which allows const expressions over fields to be used to compute lengths of arrays. Would it be possible to generate const fn getters for bit fields so I can use those in my computation?

@dzamlo
Copy link
Owner

dzamlo commented Apr 11, 2024

I wasn't able to generate const fn getters because the getter call a method from the (internal) BitRange trait which is not const. I tried to make it const but it seems to not be possible to make a method from a trait const (see rustc --explain E0379).

If you find a satisfying workaround that doesn't imply getting rid of the trait, I would be happy to implement it.

@Apanatshka
Copy link
Author

I read up on that explanation and the linked RFC. Looks like const traits aren't a thing (yet?). All I can think of to do is to generate your current BitRange implementations as loose pub const fns, generate the BitRange implementations to use those, and have the exposed macro's of bitfield use the const version so they can be const themselves. Then the users of the crate can choose between the const functions and the more convenient trait abstraction.

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