我正在阅读以下文档File:
//..
let mut file = File::create("foo.txt")?;
//..
Run Code Online (Sandbox Code Playgroud)
什么是?在这条线?我不记得以前在Rust Book中看过它了.
这是我试图执行的代码:
fn my_fn(arg1: &Option<Box<i32>>) -> (i32) {
if arg1.is_none() {
return 0;
}
let integer = arg1.unwrap();
*integer
}
fn main() {
let integer = 42;
my_fn(&Some(Box::new(integer)));
}
Run Code Online (Sandbox Code Playgroud)
(在Rust操场上)
我收到以下错误:
error[E0507]: cannot move out of borrowed content
--> src/main.rs:5:19
|
5 | let integer = arg1.unwrap();
| ^^^^ cannot move out of borrowed content
Run Code Online (Sandbox Code Playgroud)
我看到已经有很多关于借阅检查器问题的文档,但在阅读之后,我仍然无法弄清楚问题.
为什么这是一个错误,我该如何解决?
我在尝试解决机器人模拟器Exercism练习时玩得很开心,但是我遇到了一个价值转移问题,但我似乎无法解决这个问题:
impl Robot {
pub fn new(x: isize, y: isize, d: Direction) -> Self {
Robot { position: Coordinate { x: x, y: y }, direction: d }
}
pub fn turn_right(mut self) -> Self {
match self.direction {
// ...
};
self
}
pub fn turn_left(mut self) -> Self {
match self.direction {
// ...
};
self
}
pub fn advance(mut self) -> Self {
match self.direction {
// ...
};
self
}
pub fn instructions(self, instructions: …Run Code Online (Sandbox Code Playgroud)