我正在学习 Rust,我正在与借用检查器作斗争。
我有一个基本Point
结构。我有一个scale
函数可以修改该点的所有坐标。我想从另一个名为的方法调用此方法convert
:
struct AngleUnit;
struct Point {
x: f32,
y: f32,
z: f32,
unit: AngleUnit,
}
fn factor(_from: AngleUnit, _to: AngleUnit) -> f32 {
1.0
}
impl Point {
pub fn new(x: f32, y: f32, z: f32, unit: AngleUnit) -> Point {
Point { x, y, z, unit }
}
fn scale(&mut self, factor: f32) {
self.x *= factor;
self.y *= factor;
self.z *= factor;
}
fn convert(&mut self, unit: AngleUnit) {
let point_unit = self.unit;
self.scale(factor(point_unit, unit));
}
}
现在我有以下错误:
cannot move out of borrowed content
我究竟做错了什么?