let db = DB::new();
let tx = db.begin()?; // db borrowed with lifetime 'tx
let b = tx.bucket("a_bucket").unwrap(); // tx borrowed with lifetime 'p
The current API works fine, but I'd like to simplify the lifetime handling. Since 'tx: 'p in all cases, I tried to replace the 'tx lifetime with 'p so that there's only one lifetime to keep track of. The compiler gave an error that it requires 'p: 'tx, also.
Is there a way to simplify the lifetime handling so that I only need to keep track of one lifetime in the API?
If, as implied by the name, BucketCell has some kind of interior mutability, then it is invariant over 'tx, which means it cannot shrink to be smaller and thus you need two lifetimes.
Use a single lifetime param, 'bucket, for your BucketImpl definition, since by covariance of BucketCell<'_>, its 'tx lifetime parameter ought to be able to shrink down to this 'bucket lifetime parameter.
If the covariance check passes, but somehow you end up with lifetime errors down the line, then it means that some other API or usage does require "remembering how much bigger than 'bucket the original 'tx was".