有没有办法使用 Rust stable 中的不稳定模块? [英] Is there a way to use unstable modules from Rust stable?

查看:36
本文介绍了有没有办法使用 Rust stable 中的不稳定模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

不,你不能在稳定的 Rust 上使用不稳定的特性.这就是不稳定特性的全部内容:

<块引用>

在稳定版上允许不稳定的特征存在三个问题发布.

首先,正如网络多次展示的那样,仅仅是广告不稳定不起作用.一旦功能被广泛使用,它是非常很难改变它们——一旦功能可用,它就是很难阻止它们被使用.像供应商用于支持实验的网络上的前缀"反而导致了事实上的标准化.

其次,根据定义,不稳定的功能正在开发中.但该测试版/稳定版快照会在预定的时间点冻结​​该功能,而库作者将希望使用最新版本的功能.

最后,除非我们强制执行,否则我们根本无法为 Rust 提供稳定性它.我们的承诺是,如果您使用的是稳定版的 Rust,你永远不会害怕升级到下一个版本.如果图书馆可以选择不稳定,那么我们只能遵守这个承诺,如果所有图书馆作者通过支持所有三个来保证同样的事情同时发布频道.

<小时><块引用>

Rust 如何编译它的 std?

不能保证 Rust 是由稳定编译器构建的,或者它是由提供下载的同一稳定编译器构建的.拥有一个用于引导官方编译器的特殊编译器将非常简单.请参阅关于信任信任的思考 可以通过邪恶的方式做到这一点.

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

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

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

If you cannot use unstable modules with a stable compiler, how does Rust compile its std? For example, std::Vec uses alloc::raw_vec, an unstable feature.

解决方案

No, you cannot use unstable features on stable 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?

There's no guarantee that Rust is built by a stable compiler, or that it is built by the same stable compiler that is offered for download. It would be pretty straight-forward to have a special compiler that is used to bootstrap the official compiler. See Reflections on Trusting Trust for ways this could be done nefariously.

Indeed, Rust previously used a special bootstrapping compiler, but nowadays it doesn't. Instead, there's a magic configuration value that allows unstable features to be used with the stable compiler. This was done so that Linux distributions could choose to build their own versions of Rust with their own toolchains.

I don't feel it appropriate to publicly share the exact details out of respect. The effort of finding the answer should be enough to dissuade most people from using it without a good reason. It doesn't seem ideal if theres a one-line answer that anyone can trivially find using a search engine without thinking about the consequences. If one cares enough, they can research the Rust source code and build system, which is of course open.

Use a nightly version of Rust if you need to use unstable features. This is the most honest method.

这篇关于有没有办法使用 Rust stable 中的不稳定模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆