Closed sigurd4 closed 9 months ago
Surely these traits should be const (at some point),
Optionally, yes, but some types can't be const because they involve allocation, like BigUint::one()
.
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.
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 Zero
or One
for those hypothetical new traits)
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
Optionally, yes, but some types can't be const because they involve allocation, like BigUint::one().
Note: currently the #[const_trait] just marks that a trait can be implemented const.
would be maintaining a "nightly" branch be an option
I'm not interested in maintaining that... but as a branch, anyone could do this in their own fork.
would be maintaining a "nightly" branch be an option
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 const
items.
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 ZeroConstant
and OneConstant
ConstZero
and ConstOne
traits here: https://github.com/rust-num/num-traits/pull/303
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.