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
impl ConfigBuilder
Sourcepub fn host(self, host: impl ToString) -> Self
pub fn host(self, host: impl ToString) -> Self
A host or ip address to connect to.
- Defaults to
localhost.
Sourcepub fn database(self, database: impl ToString) -> Self
pub fn database(self, database: impl ToString) -> Self
The database to connect to.
- Defaults to
master.
Sourcepub fn instance_name(self, name: impl ToString) -> Self
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.
Sourcepub fn application_name(self, name: impl ToString) -> Self
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.
Sourcepub fn encryption(self, encryption: EncryptionLevel) -> Self
pub fn encryption(self, encryption: EncryptionLevel) -> Self
Set the preferred encryption level.
- With
tlsfeature, defaults toRequired. - Without
tlsfeature, defaults toNotSupported.
Sourcepub fn trust_cert(self) -> Self
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.
Sourcepub fn trust_cert_ca(self, path: impl ToString) -> Self
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.
Sourcepub fn authentication(self, auth: AuthMethod) -> Self
pub fn authentication(self, auth: AuthMethod) -> Self
Sets the authentication method.
- Defaults to
None.
Sourcepub fn readonly(self, readonly: bool) -> Self
pub fn readonly(self, readonly: bool) -> Self
Sets ApplicationIntent readonly.
- Defaults to
false.
Sourcepub 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.
pub fn client_certificate( self, cert: impl Into<PathBuf>, key: impl Into<PathBuf>, ) -> Self
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.
Sourcepub fn client_certificate_pkcs12(
self,
path: impl Into<PathBuf>,
password: impl Into<String>,
) -> Self
Available on crate features native-tls or vendored-openssl only.
pub fn client_certificate_pkcs12( self, path: impl Into<PathBuf>, password: impl Into<String>, ) -> Self
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.
Trait Implementations§
Source§impl Clone for ConfigBuilder
impl Clone for ConfigBuilder
Source§fn clone(&self) -> ConfigBuilder
fn clone(&self) -> ConfigBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more