Skip to content

Commit 013fc42

Browse files
committed
refactor: ConnectParams::prompter hands back an owned Arc
The accessor returned Option<&dyn Prompter>, a borrow that ends with the connect call it arrived on. The prompter routinely outlives that call: an interactive authentication flow gives it to the client library that will present the URL, and a driver caching the resulting credential keeps it for the life of the process. A backend could not use what it was handed, only observe it, and would have had to substitute an equivalent of its own -- the same object by luck rather than by construction, and one that would silently stop being the same the day core wraps what a driver declared. Nothing outside core consumed this yet, so the type change costs no migration.
1 parent 995beb9 commit 013fc42

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ Everything a driver has to change for the catalog rework, in one place.
9292
does that in its own `connect`, which is already the call the application is
9393
blocked in.
9494

95+
`ConnectParams::prompter()` hands back an owned `Arc`, not a borrow, because
96+
the prompter routinely outlives the `connect` it arrived on — an interactive
97+
flow gives it to the client library that presents the URL, and a driver
98+
caching the resulting credential keeps it for the process.
99+
95100
Nothing existing changes: `Backend::prompter` is defaulted to `None`, so a
96101
driver that does not implement it behaves exactly as before, and
97102
`ConnectParams`' hand-written `Debug` and its `to_connection_string` are both

‎src/types/connect_params.rs‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,17 @@ impl ConnectParams {
330330
/// `SQL_DRIVER_NOPROMPT`'s own clause in the spec says exactly that: "if the
331331
/// connection string contains enough information, the driver connects to
332332
/// the data source ... Otherwise, the driver returns SQL_ERROR."
333+
///
334+
/// Owned rather than borrowed, because the prompter routinely outlives the
335+
/// `connect` call it arrived on: an interactive flow hands it to the client
336+
/// library that will present the URL, and a driver caching the resulting
337+
/// credential keeps it for the process. A borrow ends with `connect` and
338+
/// would force every such backend to substitute an equivalent of its own,
339+
/// which is the same object by luck rather than by construction — and would
340+
/// silently stop being the same the day core wraps what a driver declared.
333341
#[must_use]
334-
pub fn prompter(&self) -> Option<&dyn Prompter> {
335-
self.prompter.as_deref()
342+
pub fn prompter(&self) -> Option<Arc<dyn Prompter>> {
343+
self.prompter.clone()
336344
}
337345

338346
/// Record the prompter this connect may use, just before

0 commit comments

Comments
 (0)