我对下面的代码有问题...
use std::collections::BTreeSet;
use maybe_owned::MaybeOwned;
struct Thing<'a, T> {
set: BTreeSet<MaybeOwned<'a, T>>
}
impl<'a, T: Ord> Thing<'a, T> {
fn take(&mut self, x: T){
let y = self.set.take(&MaybeOwned::Borrowed(&x));
}
}
给出编译器错误
error[E0597]: `x` does not live long enough
--> src/main.rs:10:53
|
8 | impl<'a, T: Ord> Thing<'a, T> {
| -- lifetime `'a` defined here
9 | fn take(&mut self, x: T){
10 | let y = self.set.take(&MaybeOwned::Borrowed(&x));
| ------------------------------------^^--
| | |
| | borrowed value does not live long enough
| argument requires that `x` is borrowed for `'a`
11 | }
| - `x` dropped here while still borrowed
然而,此时x显然没有被borrow ,因为Maybeown已超出范围,因此所附的borrow 已超出范围.
我怎样才能告诉rust编译器这没问题?