【问题标题】:Does the Rust stable standard library use unstable features?Rust stable 标准库是否使用了不稳定的特性?
【发布时间】:2021-02-10 02:57:30
【问题描述】:

在 Rust 标准库中,you can see 像这样使用 const 泛型的实现:

#[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)
    }
}

当我尝试在我的代码中做同样的事情时

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())
    }
}

我得到了错误

   --> 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

我正在使用 Rust 1.47.0。

这是否意味着 Rust 稳定的标准库是用不稳定的特性编译的?

【问题讨论】:

  • 是的,它使用了不稳定的功能。

标签: rust


【解决方案1】:
猜你喜欢
  • 1970-01-01
  • 2010-10-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多