expression
tokio-postgres: parse connection options
Connection strings can express settings compactly. Parsing checks the settings representation, not authentication or database availability. The sample contains no password and uses a reserved invalid domain. Offline example; no server is contacted. Expected stdout (not executed): port: 55432 Common mistake: Logging a real connection string containing secrets.
Formal Syntax & Structure
rust syntaxrust
let config: Config = options.parse()?;Working Example
Example Snippetrust
fn main() -> Result<(), Box<dyn std::error::Error>> { let config: tokio_postgres::Config = "host=db.example.invalid port=55432 dbname=inventory user=reader sslmode=require".parse()?; println!("port: {}", config.get_ports()[0]); Ok(())}