나는 Rust의 동시성을 사용하여 "Tower of Hanoi"게임을 구현하려고합니다. 솔직히, 나는 마지막 시간에 Rust의 일 평생을 이해하려고 노력했지만 아직 끝나지 않았습니다. 그래서 내가 이해하지 못하는 이상한 평생 실수를하게됩니다. 첫째, 여기에 코드스레딩 수명 오류
fn move_plate<'a>(stack_a: &'a mut Vec<i32>, stack_b: &'a mut Vec<i32>,
stack_c: &'a mut Vec<i32>, moves: &'a mut Vec<(i32, i32)>)
{
let mut moves1: Vec<(i32, i32)> = Vec::new();
let guard1 = Thread::scoped(
move || { move_plate(stack_a, stack_c, stack_b, (1, 3, 2), &mut moves1);
});
guard1.join().ok();
}
을의 중요한 부분입니다 그리고 여기 내가 이동에 다른 참조가 될 것이기 때문에, 기능을보다 오래 할 스레드를 방지 할 필요가 있음을 이해
error: cannot infer an appropriate lifetime due to conflicting requirements
let guard1 = Thread::scoped(move || {
move_plate(height - 1, stack_a, stack_c, stack_b, (1, 3, 2), threads, depth + 1, &mut moves1);
});
note: first, the lifetime cannot outlive the expression at 93:25...
let guard1 = Thread::scoped(move || {
note: ...so that the declared lifetime parameter bounds are satisfied
let guard1 = Thread::scoped(move || {
note: but, the lifetime must be valid for the expression at 93:45...
let guard1 = Thread::scoped(move || {
move_plate(height - 1, stack_a, stack_c, stack_b, (1, 3, 2), threads, depth + 1, &mut moves1);
});
note: ...so type `closure[]` of expression is valid during the expression
let guard1 = Thread::scoped(move || {
move_plate(height - 1, stack_a, stack_c, stack_b, (1, 3, 2), threads, depth + 1, &mut moves1);
});
error: declared lifetime bound not satisfied
let guard1 = Thread::scoped(move || {
오류를하다 지나간. 하지만 스레드에 가입 했으므로 괜찮을 것입니다. 안 그래야합니까? 그 시점에서 나는 무엇을 놓치고 있습니까? 누군가가 나를 도울 수 있다면 정말 좋을 것이다. 나는 그 멋진 (그러나 복잡한) 종류의 물건에 익숙해지고있다.