I'm using crossbeam-epoch
to write a lock-free data structure in rust. crossbeam-epoch
uses a guard
to load the heap-allocated atomic pointer. One example of the data structure's interface is:
fn get(&self, index: IndexType, guard: &'guard Guard) -> Option<&'guard Value>
This method requires a guard
which has the same lifetime with the returned value's reference.
Now, I want to wrap this method without providing a Guard
. For example:
struct ReturnType<'guard, Value> {
guard: Guard,
value: Option<&'guard Value>
}
impl<'guard, Value> MyDataStructure<Value> {
fn my_get(&self, index: IndexType) -> ReturnType<'guard, Value> {
let guard = pin();
let value = self.get(index, &guard);
ReturnType {
guard: guard,
value: value
}
}
}
But the compiler won't allow me to do this.
My question is how to implement the method my_get
?