#![deny(unused_must_use)]
use std::{fmt::Debug, num::NonZeroU16};
use serde::{Deserialize, Serialize};
pub mod pgpass;
pub use pgpass::PgPass;
#[doc(hidden)]
pub mod doctest_utils;
pub const DEFAULT_PORT: u16 = 5432;
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct Credentials {
pub hostname: String,
pub port: NonZeroU16,
pub database: String,
pub username: String,
pub password: String,
}
impl From<Credentials> for postgres::Config {
fn from(value: Credentials) -> Self {
let mut config = Self::new();
config
.host(&value.hostname)
.port(value.port.get())
.dbname(&value.database)
.user(&value.username)
.password(&value.password);
config
}
}
impl Debug for Credentials {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Credentials")
.field("hostname", &self.hostname)
.field("port", &self.port)
.field("database", &self.database)
.field("username", &self.username)
.field("password", &"[ Censored ]")
.finish()
}
}