Skip to main content

ConfigBuilder

Struct ConfigBuilder 

Source
pub struct ConfigBuilder { /* private fields */ }
Expand description

A builder for Config, providing an ergonomic, chainable way to construct a connection configuration.

Create a builder with Config::builder, set the desired options by calling its methods (each returns the builder to allow chaining) and finalize it with build.

§Example

let config = Config::builder()
    .host("localhost")
    .port(1433)
    .database("master")
    .encryption(EncryptionLevel::NotSupported)
    .authentication(AuthMethod::sql_server("SA", "<password>"))
    .build();

Implementations§

Source§

impl ConfigBuilder

Source

pub fn host(self, host: impl ToString) -> Self

A host or ip address to connect to.

  • Defaults to localhost.
Source

pub fn port(self, port: u16) -> Self

The server port.

  • Defaults to 1433.
Source

pub fn database(self, database: impl ToString) -> Self

The database to connect to.

  • Defaults to master.
Source

pub fn instance_name(self, name: impl ToString) -> Self

The instance name as defined in the SQL Browser. Only available on Windows platforms.

If specified, the port is replaced with the value returned from the browser.

  • Defaults to no name specified.
Source

pub fn application_name(self, name: impl ToString) -> Self

Sets the application name to the connection, queryable with the APP_NAME() command.

  • Defaults to no name specified.
Source

pub fn encryption(self, encryption: EncryptionLevel) -> Self

Set the preferred encryption level.

  • With tls feature, defaults to Required.
  • Without tls feature, defaults to NotSupported.
Source

pub fn trust_cert(self) -> Self

If set, the server certificate will not be validated and it is accepted as-is.

On production setting, the certificate should be added to the local key storage (or use trust_cert_ca instead), using this setting is potentially dangerous.

§Panics

Will panic in case trust_cert_ca was called before.

  • Defaults to default, meaning server certificate is validated against system-truststore.
Source

pub fn trust_cert_ca(self, path: impl ToString) -> Self

If set, the server certificate will be validated against the given CA certificate in in addition to the system-truststore. Useful when using self-signed certificates on the server without having to disable the trust-chain.

§Panics

Will panic in case trust_cert was called before.

  • Defaults to validating the server certificate is validated against system’s certificate storage.
Source

pub fn authentication(self, auth: AuthMethod) -> Self

Sets the authentication method.

  • Defaults to None.
Source

pub fn readonly(self, readonly: bool) -> Self

Sets ApplicationIntent readonly.

  • Defaults to false.
Source

pub fn client_certificate( self, cert: impl Into<PathBuf>, key: impl Into<PathBuf>, ) -> Self

Available on crate features native-tls or rustls or vendored-openssl only.

Supplies a client certificate and private key for mutual TLS.

See Config::client_certificate for details and backend support.

Source

pub fn client_certificate_pkcs12( self, path: impl Into<PathBuf>, password: impl Into<String>, ) -> Self

Available on crate features native-tls or vendored-openssl only.

Supplies a client identity from a PKCS#12 / PFX bundle for mutual TLS.

See Config::client_certificate_pkcs12 for details and backend support.

Source

pub fn build(self) -> Config

Produces the finalized Config from this builder.

Trait Implementations§

Source§

impl Clone for ConfigBuilder

Source§

fn clone(&self) -> ConfigBuilder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ConfigBuilder

Source§

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

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

impl From<Config> for ConfigBuilder

Source§

fn from(config: Config) -> Self

Converts to this type from the input type.
Source§

impl From<ConfigBuilder> for Config

Source§

fn from(builder: ConfigBuilder) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more