I have the following code:
struct BufferPool {}
struct Buffer<'a> {
pool: &'a BufferPool,
}
impl BufferPool {
pub fn alloc(&self) -> Buffer<'_> {
Buffer { pool: self }
}
}
struct User {
pool: BufferPool,
buffer: Buffer<'what_lifetime_here?>,
}
The buffer object in the User struct is guaranteed to be allocated by the pool object in the same struct, as long as the pool object in the User struct is valid, buffer is valid too. But buffer requires a lifetime specifier, I am wondering if I can borrow the lifetime of the pool object for buffer, or do I have to lift the lifetime of the object that buffer depends on from the pool object to the User object like: struct User<'a>? Or there's another way around?