Struct Config

Source
pub struct Config { /* private fields */ }

Implementations§

Source§

impl Config

Source

pub const fn new() -> Config

Creates a new configuration.

Source

pub fn user(&mut self, user: &str) -> &mut Config

Sets the user to authenticate with.

Required.

Source

pub fn get_user(&self) -> Option<&str>

Gets the user to authenticate with, if one has been configured with the user method.

Source

pub fn password<T>(&mut self, password: T) -> &mut Config
where T: AsRef<[u8]>,

Sets the password to authenticate with.

Source

pub fn get_password(&self) -> Option<&[u8]>

Gets the password to authenticate with, if one has been configured with the password method.

Source

pub fn dbname(&mut self, dbname: &str) -> &mut Config

Sets the name of the database to connect to.

Defaults to the user.

Source

pub fn get_dbname(&self) -> Option<&str>

Gets the name of the database to connect to, if one has been configured with the dbname method.

Source

pub fn options(&mut self, options: &str) -> &mut Config

Sets command line options used to configure the server.

Source

pub fn get_options(&self) -> Option<&str>

Gets the command line options used to configure the server, if the options have been set with the options method.

Source

pub fn application_name(&mut self, application_name: &str) -> &mut Config

Sets the value of the application_name runtime parameter.

Source

pub fn get_application_name(&self) -> Option<&str>

Gets the value of the application_name runtime parameter, if it has been set with the application_name method.

Source

pub fn ssl_mode(&mut self, ssl_mode: SslMode) -> &mut Config

Sets the SSL configuration.

Defaults to prefer.

Source

pub fn get_ssl_mode(&self) -> SslMode

Gets the SSL configuration.

Source

pub fn ssl_negotiation( &mut self, ssl_negotiation: SslNegotiation, ) -> &mut Config

Sets the SSL negotiation method.

Defaults to postgres.

Source

pub fn get_ssl_negotiation(&self) -> SslNegotiation

Gets the SSL negotiation method.

Source

pub fn host(&mut self, host: &str) -> &mut Config

Source

pub fn host_path<T>(&mut self, host: T) -> &mut Config
where T: AsRef<Path>,

Adds a Unix socket host to the configuration.

Unlike host, this method allows non-UTF8 paths.

Source

pub fn get_hosts(&self) -> &[Host]

Gets the hosts that have been added to the configuration with host.

Source

pub fn port(&mut self, port: u16) -> &mut Config

Adds a port to the configuration.

Multiple ports can be specified by calling this method multiple times. There must either be no ports, in which case the default of 5432 is used, a single port, in which it is used for all hosts, or the same number of ports as hosts.

Source

pub fn get_ports(&self) -> &[u16]

Gets the ports that have been added to the configuration with port.

Source

pub fn target_session_attrs( &mut self, target_session_attrs: TargetSessionAttrs, ) -> &mut Config

Sets the requirements of the session.

This can be used to connect to the primary server in a clustered database rather than one of the read-only secondary servers. Defaults to Any.

Source

pub fn get_target_session_attrs(&self) -> TargetSessionAttrs

Gets the requirements of the session.

Source

pub fn tls_server_end_point( &mut self, tls_server_end_point: impl AsRef<[u8]>, ) -> &mut Self

change the remote peer’s tls certificates. it’s often coupled with Postgres::connect_io API for manual tls session connecting and channel binding authentication.

§Examples
use xitca_postgres::{Config, Postgres};

// handle tls connection on your own.
async fn connect_io() {
    let mut cfg = Config::try_from("postgres://postgres:postgres@localhost/postgres").unwrap();
     
    // an imaginary function where you establish a tls connection to database on your own.
    // the established connection should be providing valid cert bytes.
    let (io, certs) = your_tls_connector().await;

    // set cert bytes to configuration
    cfg.tls_server_end_point(certs);

    // give xitca-postgres the config and established io and finish db session process.
    let _ = Postgres::new(cfg).connect_io(io).await;
}

async fn your_tls_connector() -> (MyTlsStream, Vec<u8>) {
    todo!("your tls connecting logic lives here. the process can be async or not.")
}

// a possible type representation of your manual tls connection to database
struct MyTlsStream;
Source

pub fn get_tls_server_end_point(&self) -> Option<&[u8]>

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Config

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Config

Source§

fn eq(&self, other: &Config) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&str> for Config

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(s: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<String> for Config

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(s: String) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for Config

Source§

impl StructuralPartialEq for Config

Auto Trait Implementations§

§

impl Freeze for Config

§

impl RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnwindSafe for Config

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V