设置在无限循环之外的可见性填充它

时间:2016-10-05 11:51:24

标签: rust

我在HashSet之外定义loop,最终会填充它。

类似的东西:

let mut keys = HashSet::new();
loop {
    let mss = try!(con.poll()); // taken from kafka-rust
    // some code
    keys.insert(stuff);
    // some code
    try!(con.commit_consumed());
}

现在我有明显的reference must be valid for the block suffix following statement

note: reference must be valid for the block suffix following statement 1 at 28:34...
  --> src/main.rs:28:35
   |
28 |     let mut keys = HashSet::new();
   |                                   ^
note: ...but borrowed value is only valid for the block suffix following statement 0 at 30:35
  --> src/main.rs:30:36
   |
30 |         let mss = try!(con.poll());
   |                                    ^

error: aborting due to previous error

这样做的正确方法是什么?

0 个答案:

没有答案