rust - 用于更大切片的 IntoIterator
问题描述
我正在尝试编写一个使用RegexSet
. 这是使用它的代码。
fn main() {
let path_regex = regex::RegexSet = regex::RegexSet::new(&[
r"^/api/$",
...
r"^/logs/$",
r"^/logs/(?P<logpath>[^/?#]*)$",
r"^/version/$"
]).unwrap();
}
传递给的切片RegexSet
有 346 个元素。当我运行这个时,我得到
error[E0277]: `&[&str; 346]` is not an iterator
--> src/server/mod.rs:650:60
|
650 | pub static ref GLOBAL_REGEX_SET: regex::RegexSet = regex::RegexSet::new(&[
| ^^^^^^^^^^^^^^^^^^^^ `&[&str; 346]` is not an iterator
|
= help: the trait `std::iter::Iterator` is not implemented for `&[&str; 346]`
= note: required because of the requirements on the impl of `std::iter::IntoIterator` for `&[&str; 346]`
= note: required by `server::paths::regex::RegexSet::new`
查看文档,IntoIterator
仅针对大小不超过 32 的数组实现
我试图实现该特征,导致错误
error[E0119]: conflicting implementations of trait `std::iter::IntoIterator` for type `&[_; 346]`:
--> src/server/mod.rs:651:5
|
651 | impl<'a, T> IntoIterator for &'a [T; 346] {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<I> std::iter::IntoIterator for I
where I: std::iter::Iterator;
= note: upstream crates may add new impl of trait `std::iter::Iterator` for type `&[_; 346]` in future versions
我该如何解决这个问题?
解决方案
推荐阅读
- c++ - OpenGL构建层次变换系统
- python - 在 Python 中使用继承时,在派生类中错误地调用了派生类中具有相同名称的方法
- python - 使用 Python OCR 在窗口上搜索文本
- linux - CSI 摄像头驱动程序不显示 ffplay 的输出
- django - 在 Django 3.2.2 版中更改 DateTimeField 格式
- sql - SQL 帮助以块的形式“透视”表
- java - SPEL:如何从地图中获取多个值并保持格式化
- c++ - 如果模板从未在未评估的上下文之外被调用,是否返回 declval UB?
- date - DAX 如何在范围内填充缺失的日期(报表生成器)
- node.js - ProcessContainerFork.js pm2“意外令牌导入”节点 14