小编mup*_*909的帖子

在 for 循环内访问迭代器

我正在 Rust 中测试自定义双向迭代器,但遇到了错误

error[E0382]: borrow of moved value: `iter`
   --> src/main.rs:40:13
    |
37  |     let mut iter = BiIterator::from(vec![1, 2, 3]);
    |         -------- move occurs because `iter` has type `BiIterator<i32>`, which does not implement the `Copy` trait
38  |     for i in iter {
    |              ----
    |              |
    |              `iter` moved due to this implicit call to `.into_iter()`
    |              help: consider borrowing to avoid moving into the for loop: `&iter`
39  |         if i == 3 {
40  |             iter.position(0); …
Run Code Online (Sandbox Code Playgroud)

iteration iterator for-loop move-semantics rust

4
推荐指数
1
解决办法
1197
查看次数

有没有办法从 Rust 中的 &amp;str 类型获取函数指针(由 use 提供)

有没有办法从用户提供的 Rust 中的 &str 类型获取函数指针。示例: use 提供了用户提供的函数名称我需要某种方式来调用该函数,最好是闭包或函数指针

closures function rust

1
推荐指数
1
解决办法
258
查看次数