rust - Unresolved import `core::array::FixedSizeArray`
问题描述
I am new to Rust.
I've been given some Rust code to work with but the cargo build fails with error "unresolved import core::array::FixedSizeArray
". In what way can I remove the error?
I'm using version 1.57.0 nightly; do not know which version of Rust the code base has been build successfully last time.
The code also uses a lot of '#![feature(...)]', which could not be used with stable version. How do I map a feature in older version's nightly build to the current version's functions/etc.? Example of features: #![feature(vec_resize_default)] #![feature(fixed_size_array)]
Thanks.
解决方案
最后一个版本FixedSizeArray
是 1.52.1 版本。它被设计用于在不合适[T; N]
的情况下&[T]
一般使用固定大小的数组。AsRef<[T]>
但即使在跟踪问题中,它的用处也是有限的,最终会被min_const_generics
1.51.0 版本中稳定的功能所掩盖。
您将不得不将夜间版本降级回 1.52.1 或更早版本,或者修复由其删除引起的问题。没有办法只在较新版本上使用已删除的功能。
替换此功能的一些选项:
[T; N]
可以使用 const 泛型直接将其转换为形式。struct MyStruct<A: FixedSizeArray> { data: A } fn make_my_struct<A: FixedSizeArray>(data: A) -> MyStruct<A> { MyStruct { data } }
会成为:
struct MyStruct<T, const N: usize> { data: [T; N] } fn make_my_struct<T, const N: usize>(data: [T; N]) -> MyStruct<T, N> { MyStruct { data } }
也许您一开始并不需要它,只需使用
&[T]
or就可以了AsRef<[T]>
。做你自己的特质。
FixedSizeArray
不需要任何编译器魔法,但要为所有数组类型实现它,无论如何你都必须使用上面的方法#1。
推荐阅读
- excel - 比较两列 onEdit,如果匹配,则将新添加的颜色着色
- python - 为什么我在给定的 python 代码中不断出错?
- javascript - 如何使用 jquery ajax 和 Php 在按钮单击时加载页面?
- c# - 可以使用 EAGER LOADING 代替 JOINS 吗?
- java - 我想加 10% 的服务税和 13% 的增值税,但我做不到
- java - 无法从数据源获取连接
- javascript - 如何根据用户的请求生成多个输入?
- javascript - 使用具有特定移动规则的 DFS 生成迷宫
- python - AttributeError:使用 coursera-dl 包时,“模块”对象在 Windows 上没有属性“PROTOCOL_TLSv1_2”
- if-statement - 我想避免在下面的代码中出现其他情况,有什么建议吗?