2

In the Rust standard library, you can see implementations like this which use const generics:

#[stable(feature = "vec_from_array", since = "1.44.0")]
impl<T, const N: usize> From<[T; N]> for Vec<T> {
    #[cfg(not(test))]
    fn from(s: [T; N]) -> Vec<T> {
        <[T]>::into_vec(box s)
    }
    #[cfg(test)]
    fn from(s: [T; N]) -> Vec<T> {
        crate::slice::into_vec(box s)
    }
}

When I try to do the same in my code

impl<const N: usize> From<[u8; N]> for Binary {
    fn from(source: [u8; N]) -> Self {
        // Implementation available for $N <= 32.
        // Requires https://caniuse.rs/features/vec_from_array, avaiable since Rust 1.44.0.
        Self(source.into())
    }
}

I get the error

   --> packages/std/src/binary.rs:105:12
    |
105 | impl<const N: usize> From<[u8; N]> for Binary {
    |            ^
    |
    = note: see issue #74878 <https://github.com/rust-lang/rust/issues/74878> for more information

I'm using Rust 1.47.0.

Does this mean the Rust stable standard library is compiled with unstable features?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Simon Warta
  • 10,850
  • 5
  • 40
  • 78