rust - 编译错误 len 作为 const fn 还不稳定
问题描述
我的依赖项之一出现错误。这是错误的代码示例:bytes
0.5.2
pub const fn foo(foo: &'static [u8]) -> usize {
foo.len()
}
error: `core::slice::<impl [T]>::len` is not yet stable as a const fn
--> <source>:2:5
|
2 | foo.len()
| ^^^^^^^^^
error: aborting due to previous error
active toolchain
----------------
stable-x86_64-pc-windows-msvc (default) rustc 1.38.0 (625451e37 2019-09-23)
解决方案
这0.5.x
似乎需要 Rust 1.39,因此最简单的选择可能是升级到最新版本。
错误状态
core::slice::<impl [T]>::len
作为 const fn 还不稳定
如果您查看发行说明,1.39
您可以看到其中一个条目是
str::len
,[T]::len
现在str::as_bytes
是 const 函数
所以这个箱子特别需要 >=1.39
推荐阅读
- mysql - 如果一列值相等而另一列不相等,则忽略 SQL 中的一行
- css - 充当表格行的表格列
- php - 如何获取当前用户登录 Laravel 的时间?
- python - BeautifulSoup:提取“img alt”文本
- android - 如何使构造函数中带有 id 参数的 ViewModelFactory 可注入?
- android - Toast lengthLong 和 lengthShort 有什么区别?
- vb.net - VB.Net:检查应用程序是否首次运行时出错
- python - tkinter 使用主窗口调整框架和内容的大小
- sql - 如何在 SQL 中找到供应商提供的所有零件的供应商编号?
- c++ - Pthread 行为 C++