Replies: 2 comments
-
@rix0rrr The issue you are encountering is attempting a self-reference in a For a brief explanation: 👉 So, I would advise against trying to do this. Instead, try to ensure that Feel free to post your new design. |
Beta Was this translation helpful? Give feedback.
-
This is essentially the same issue that I'm grappling with in #69. The requirement to keep the DatabaseBuilder around for the same life as Database is less than intuitive, I'd say, and actually nearly impossible to do in stateful applications without some hacky-feeling workarounds. It looks like the creator of redb intends on removing as many lifetimes as possible from the public API for 2.0, based on a checklist item in cberner/redb#677 (and some of it has happened in cberner/redb#732). Hopefully that comes to fruition, as the lifetimes are making it tough to work with. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I'm trying to use
native_db
, but I have a feeling I'm doing something wrong...I'd like to hide the concern of how my database is implemented, so I'd like to hide the implementation details in a
struct
with some methods. But the combination ofDatabaseBuilder
andDatabase
which borrows the builder is making this hard.My first attempt was this, but the lifetime I have to pass into the
Database
leads to a parameter that I don't actually want to give. I want to pass a lifetime like'self
or'this
or something, but that doesn't exist:It also becomes nearly impossible to implement the initializer for this struct:
I was ultimately somewhat able to make it work by doing contortions, by putting the
Database
into anOption<>
and initializing it after construction.This doesn't feel ideal, and everywhere I want to accept the database now I'm still stuck with that annoying lifetime parameter.
Another thing I figured I could do is just store the builder, and open and close the database on every mutation. But, I don't know. It's not clear to me that how it was designed to be used, and it intuitively feels wasteful to do that.
So here's my question: how should I put a database connection inside a struct?
Beta Was this translation helpful? Give feedback.
All reactions