我有两个结构体:
struct MyVector {
storage: Vec<u32>,
}
struct MyVectorBuilder {
storage: Vec<u32>,
}
impl MyVectorBuilder {
fn new() -> MyVectorBuilder {
MyVectorBuilder { storage: Vec::new() }
}
fn build_my_vector(&mut self) -> MyVector {
// Doesn't compile: ^^^^ cannot move out of borrowed content
MyVector { storage: self.storage }
}
}
有没有办法告诉编译器,build_my_vector()
调用后将不再使用 MyVectorBuilder
,以便让我将 storage
移动到 MyVector
?