I am trying to implement Deref
for my struct:
use std::cell::{RefCell, RefMut};
use std::ops::Deref;
use std::rc::Rc;
fn main() {
let x = VariableData {
data: Rc::new(RefCell::new(Vec::new())),
};
x.push(6);
}
struct VariableData {
data: Rc<RefCell<Vec<u32>>>,
}
impl<'a> Deref for VariableData {
type Target = RefMut<'a, Vec<u32>>;
fn deref(&self) -> &Self::Target {
self.data.borrow_mut()
}
}
But I get the following error:
error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates
--> src/main.rs:17:6
|
17 | impl<'a> Deref for VariableData {
| ^^ unconstrained lifetime parameter
How do I specify that 'a
is at most the lifetime of VariableData
?