You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because Connection is created within the scope of the method from a borrowed self, the original env reference is no longer valid, at least until conn is dropped. This means you can't move Connection out of that scope and can only go into inner scopes. This isn't necessarily ideal, as you can't even assign env/conn to struct fields.
I would suggest instead doing Connection::from_connection_string(&conn_str, &env). Env would only be borrowed for that scope of the method unless you borrow a field from Env for Conn.
The text was updated successfully, but these errors were encountered:
ZerothLaw
changed the title
connection_with_connection_string borrows Environment preventing you from moving instances to a higher scope
connect_with_connection_string borrows Environment preventing you from moving instances to a higher scope
Jun 28, 2018
Looking closer at the source code, I notice that inside Environment/mod.rs the as_safe call creates a borrowed reference to an inner field of Environment.
@ZerothLaw Thanks for your question. I'm not sure if I understand it correctly, but just to be on the same wave I need to mention that you supposed to have only one Env instance per your whole application (perhaps inside lazy_static or something). According to ODBC spec you shouldn't allocate more than one environment handle (which exactly what create_environment_v3() does). So it's better not to call this method on every connection creation.
You can see a very simple example of multiple connections handling in r2d2-odbc crate - maybe it's source code will somehow help you with yours implementation.
Consider this code:
Because Connection is created within the scope of the method from a borrowed self, the original env reference is no longer valid, at least until conn is dropped. This means you can't move Connection out of that scope and can only go into inner scopes. This isn't necessarily ideal, as you can't even assign env/conn to struct fields.
I would suggest instead doing Connection::from_connection_string(&conn_str, &env). Env would only be borrowed for that scope of the method unless you borrow a field from Env for Conn.
The text was updated successfully, but these errors were encountered: