-
Notifications
You must be signed in to change notification settings - Fork 136
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
Make Zero and One const traits #276
Conversation
Optionally, yes, but some types can't be const because they involve allocation, like
Yeah, I don't want to deal with unstable features in general. Definitely not unconditional, but even putting it behind a "nightly" cargo feature would be work to keep up, and especially here given that const traits are in flux lately. |
Could there be separate traits with associated constants for zero and one? (and potentially, a blanket impl of That could be a purely additive change that would also have the benefit of working on stable Rust. |
would be maintaining a "nightly" branch be an option #283
Note: currently the #[const_trait] just marks that a trait can be implemented const. |
I'm not interested in maintaining that... but as a branch, anyone could do this in their own fork. |
Ok. Hopefully const generics become stable soon. If/When my need for this arises again I will create a fork. Once I do this I will mention this issue |
I think it'd be possible to get similar benefits in a purely additive manner through a separate trait which defines them as consts, and could be linked to the existing traits via blanket impls: pub trait ZeroConst: Sized {
const ZERO: Self;
}
impl<T> Zero for T
where
T: Add<Self, Output = Self> + Eq + ZeroConst
{
fn zero() -> Self {
Self::ZERO
}
fn is_zero(&self) -> bool {
self.eq(&Self::ZERO)
}
} |
I would be open to separate traits with |
Just chiming in to say I'd love this feature too, and doing it as separate traits would be perfectly acceptable |
I opened a PR which adds |
With #303 merged I think this can be closed? |
Hi, i'm a a big fan of this library, and use it often. I'm currently working on some libraries using compile-time traits and functions, and figured it would be very convenient if the zero and one traits in your library are const traits.
Surely these traits should be const (at some point), however this requires enabling experimental language features, which i'm not sure is desireable at this point. I can understand if you guys want to wait with that until const traits are a stable rust language feature.