Rust 移动对象,然后调用使用对象自身的方法,会产生“无法移出借用的内容”

Rust 移动对象,然后调用使用对象自身的方法,会产生“无法移出借用的内容”,rust,borrow-checker,Rust,Borrow Checker,我知道关于这个问题有1000个问题,但我读到的似乎没有一个适合这个问题 我正在做的是,在某个特定功能中,我正在从rusoto_s3板条箱创建一个rusoto未来: fn execute(&mut self, s3: &S3Client) -> (i64, RusotoFuture<GetObjectOutput, GetObjectError>) { ... let dl = s3.get_object(GetObjectRequest{

我知道关于这个问题有1000个问题,但我读到的似乎没有一个适合这个问题

我正在做的是,在某个特定功能中,我正在从rusoto_s3板条箱创建一个rusoto未来:

fn execute(&mut self, s3: &S3Client) -> (i64, RusotoFuture<GetObjectOutput, GetObjectError>) {
   ...
   let dl = s3.get_object(GetObjectRequest{
        ...
        ..Default::default()
    });
   return (sz, dl);
稍后我想从handle_op函数调用此对象上的sync,问题是签名会消耗self:

致电:

op.execute(self.pending.as_mut().unwrap() );
错误是:

let result = req.sync().expect("could not head");
             ^^^ cannot move out of borrowed content
我怎样才能做到这一点?我是否可以强制某些不安全的机制拥有它?
我也在看盒子,但我得到了同样的错误。不过,很可能我没有正确使用它。

签名会消耗自己,因为在它解决后保留未来没有多大意义。所以你不应该对引用调用sync。但你的问题并不清楚什么叫什么:

let result = req.sync().expect("could not download");
let result = req.sync().expect("could not head");
         ^^^ cannot move out of borrowed content
这些是同一行,您更改了字符串,还是不同的行e.t.c

但我仍然可以试着回答

let dl = s3.get_object(GetObjectRequest{
    ...
    ..Default::default()
});
get_对象返回的RusotoFuture不是引用,因此

fn handle_op(&mut self, input: u64) {
   ...
   let (sz, dl) = op.execute( &self.s3.as_ref().unwrap() );
   self.pending = Some(dl);
具有可消费的d1,即使它将&mut self作为参数。 因此,您应该将execute函数从

fn execute(&mut self, req: &mut RusotoFuture<GetObjectOutput, GetObjectError>) {...}
您的设置中有什么不可能的原因吗?

很可能是op.executeself.pending。。。;借用req,以便以后不能通过调用req.sync来使用它。但如果没有,就很难说了。
let dl = s3.get_object(GetObjectRequest{
    ...
    ..Default::default()
});
fn handle_op(&mut self, input: u64) {
   ...
   let (sz, dl) = op.execute( &self.s3.as_ref().unwrap() );
   self.pending = Some(dl);
fn execute(&mut self, req: &mut RusotoFuture<GetObjectOutput, GetObjectError>) {...}
fn execute(&mut self, req: RusotoFuture<GetObjectOutput, GetObjectError>) {...}
op.execute( self.pending.take() );