expression

tokio-postgres: configure a connection

A Config describes where and how a connection will be established. Constructing it does not contact a server. An external deployment must supply a TLS connector that verifies the certificate and server identity, and obtain credentials through approved secret storage. Print only non-secret fields. Offline example; no server is contacted. Expected stdout (not executed): database: inventory Common mistake: Assuming SslMode::Require alone verifies the server identity; that depends on the connector.

Formal Syntax & Structure

rust syntaxrust
Config::new().host(host).dbname(database).user(user)

Working Example

Example Snippetrust
fn main() -> Result<(), Box<dyn std::error::Error>> {    use tokio_postgres::{Config, config::SslMode};    let mut config = Config::new();    config.host("db.example.invalid").dbname("inventory").user("reader")        .ssl_mode(SslMode::Require);    println!("database: {}", config.get_dbname().unwrap_or("missing"));    Ok(())}
Rust Reference