rust - 有没有办法使用 Rust stable 中的不稳定模块?

标签 rust

如果你不能用稳定的编译器使用不稳定的模块,Rust 如何编译它的 std?例如,std::Vec 使用了 alloc::raw_vec,这是一个不稳定的特性。

最佳答案

不,您不能在稳定的 Rust 上使用不稳定的功能。 That's the entire point of unstable features :

There are three problems with allowing unstable features on the stable release.

First, as the web has shown numerous times, merely advertising instability doesn’t work. Once features are in wide use it is very hard to change them – and once features are available at all, it is very hard to prevent them from being used. Mechanisms like “vendor prefixes” on the web that were meant to support experimentation instead led to de facto standardization.

Second, unstable features are by definition work in progress. But the beta/stable snapshots freeze the feature at scheduled points in time, while library authors will want to work with the latest version of the feature.

Finally, we simply cannot deliver stability for Rust unless we enforce it. Our promise is that, if you are using the stable release of Rust, you will never dread upgrading to the next release. If libraries could opt in to instability, then we could only keep this promise if all library authors guaranteed the same thing by supporting all three release channels simultaneously.


How does Rust compile its std?

不能保证 Rust 是由稳定的编译器构建的,或者它是由可供下载的同一个稳定编译器构建的。拥有一个用于引导官方编译器的特殊编译器会非常简单。参见 Reflections on Trusting Trust寻找可以恶意完成的方法。

的确,Rust 之前使用了一种特殊的引导编译器,但是 nowadays it doesn't .相反,有一个神奇的配置值允许不稳定的特性与稳定的编译器一起使用。这样做是为了让 Linux 发行版可以选择使用自己的工具链构建自己的 Rust 版本。

出于尊重,我认为公开分享具体细节不合适。寻找答案的努力应该足以阻止大多数人在没有充分理由的情况下使用它。如果有一个任何人都可以使用搜索引擎轻松找到而无需考虑后果的单行答案,这似乎并不理想。如果足够关心,他们可以研究 Rust 源代码并构建系统,这当然是开放的。

如果您需要使用不稳定的功能,请使用每晚版本的 Rust。这是最诚实的方法。

关于rust - 有没有办法使用 Rust stable 中的不稳定模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42048589/

相关文章:

rust - 枚举变体大小过大导致的性能问题的解决方案

memory - 为什么 size_of 可以用于未确定大小的类型?

scope - "does not live long enough"创建可在线程间传递的引用二叉树时

algorithm - 从 Vec<String> 构建 UrlTree

rust - 如何在成员函数中修改结构的可选字段

rust - 如何设置 (Rust) Rocket API 端点模板响应的 HTTP 状态代码?

rust - 无法创建 hyper::Client,因为编译器无法推断出足够的类型信息

rust - 选项<Receiver> 在上一次循环迭代中移动

iterator - 在嵌套迭代器中指定生命周期以进行展平

rust - Rayon 折叠成一个 HashMap