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

Is it possible to make basic ops const-fn? #9

Closed
Boscop opened this issue Apr 4, 2018 · 5 comments
Closed

Is it possible to make basic ops const-fn? #9

Boscop opened this issue Apr 4, 2018 · 5 comments

Comments

@Boscop
Copy link

Boscop commented Apr 4, 2018

Is it possible to make basic ops const-fn? E.g. fn mul(self, r: T) -> Self::Output.

To allow them to be used in constant initializations (without incurring the overhead of lazy_static).

@kornelski
Copy link
Owner

kornelski commented Apr 4, 2018

I think const fn isn't stable yet? Other than that I agree it's a good idea and I think it should be possible to do for most functions.

@owenthewizard
Copy link
Contributor

It's not stable now?

@kornelski
Copy link
Owner

Yup, it's stable and good to go!

@ripytide
Copy link
Contributor

While I understand that const fn is now stable, const fn in trait is not yet stable so the example provided of fn mul(self, r: T) -> Self::Output is (at the time of writing) not yet able to become const fn mul(self, r: T) -> Self::Output since it belongs to the trait Mul. Currently, the only const fn methods I can see in this crate are the new() -> Self methods, but as changes from not_const to const on inherent methods is backwards compatible I don't see this as high priority for #64.

@kornelski kornelski closed this as not planned Won't fix, can't repro, duplicate, stale Jul 4, 2024
@kornelski
Copy link
Owner

I was initially thinking about just inherent functions. The std::ops is unlikely to be const in the foreseeable future.

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

4 participants