Skip to main content

DbResolver

Trait DbResolver 

Source
pub trait DbResolver:
    Send
    + Sync
    + 'static {
    // Required method
    fn resolve(&self, name: &str) -> Option<Arc<Db>>;

    // Provided method
    fn token(&self) -> Option<String> { ... }
}
Expand description

How a caller resolves a database name to an open Db.

A trait object rather than a concrete handle so this module does not depend on server::Manager — which keeps the protocol code unit-testable against a plain Db with no HTTP stack in the way.

Required Methods§

Source

fn resolve(&self, name: &str) -> Option<Arc<Db>>

Look up an open database by the name the client connected with.

MAY BLOCK. The implementation is allowed to take a lock, so this is always called from spawn_blocking — never on an async worker. Taking a tokio RwLock::blocking_read() on a runtime thread panics outright (“Cannot block the current thread from within a runtime”), which is exactly how the first cut of this failed.

Provided Methods§

Source

fn token(&self) -> Option<String>

The bearer token, when one is configured. None = open access.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl DbResolver for Manager

Start the nedbd v2 server. Lets the Postgres read endpoint share this process’s already-open databases instead of opening its own handles — which the exclusive data-dir LOCK would refuse anyway, and rightly so.