ClientOptions

Struct ClientOptions 

Source
#[non_exhaustive]
pub struct ClientOptions {
Show 22 fields pub hosts: Vec<StreamAddress>, pub app_name: Option<String>, pub cmap_event_handler: Option<Arc<dyn CmapEventHandler>>, pub command_event_handler: Option<Arc<dyn CommandEventHandler>>, pub connect_timeout: Option<Duration>, pub credential: Option<Credential>, pub direct_connection: Option<bool>, pub driver_info: Option<DriverInfo>, pub heartbeat_freq: Option<Duration>, pub local_threshold: Option<Duration>, pub max_idle_time: Option<Duration>, pub max_pool_size: Option<u32>, pub min_pool_size: Option<u32>, pub read_concern: Option<ReadConcern>, pub repl_set_name: Option<String>, pub retry_reads: Option<bool>, pub retry_writes: Option<bool>, pub selection_criteria: Option<SelectionCriteria>, pub server_selection_timeout: Option<Duration>, pub tls: Option<Tls>, pub wait_queue_timeout: Option<Duration>, pub write_concern: Option<WriteConcern>, /* private fields */
}
Expand description

Contains the options that can be used to create a new Client.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§hosts: Vec<StreamAddress>

The initial list of seeds that the Client should connect to.

Note that by default, the driver will autodiscover other nodes in the cluster. To connect directly to a single server (rather than autodiscovering the rest of the cluster), set the direct field to true.

§app_name: Option<String>

The application name that the Client will send to the server as part of the handshake. This can be used in combination with the server logs to determine which Client is connected to a server.

§cmap_event_handler: Option<Arc<dyn CmapEventHandler>>

The handler that should process all Connection Monitoring and Pooling events. See the CmapEventHandler type documentation for more details.

§command_event_handler: Option<Arc<dyn CommandEventHandler>>

The handler that should process all command-related events. See the CommandEventHandler type documentation for more details.

§connect_timeout: Option<Duration>

The connect timeout passed to each underlying TcpStream when attemtping to connect to the server.

The default value is 10 seconds.

§credential: Option<Credential>

The credential to use for authenticating connections made by this client.

§direct_connection: Option<bool>

Specifies whether the Client should directly connect to a single host rather than autodiscover all servers in the cluster.

The default value is false.

§driver_info: Option<DriverInfo>

Extra information to append to the driver version in the metadata of the handshake with the server. This should be used by libraries wrapping the driver, e.g. ODMs.

§heartbeat_freq: Option<Duration>

The amount of time each monitoring thread should wait between sending an isMaster command to its respective server.

The default value is 10 seconds.

§local_threshold: Option<Duration>

When running a read operation with a ReadPreference that allows selecting secondaries, local_threshold is used to determine how much longer the average round trip time between the driver and server is allowed compared to the least round trip time of all the suitable servers. For example, if the average round trip times of the suitable servers are 5 ms, 10 ms, and 15 ms, and the local threshold is 8 ms, then the first two servers are within the latency window and could be chosen for the operation, but the last one is not.

A value of zero indicates that there is no latency window, so only the server with the lowest average round trip time is eligible.

The default value is 15 ms.

§max_idle_time: Option<Duration>

The amount of time that a connection can remain idle in a connection pool before being closed. A value of zero indicates that connections should not be closed due to being idle.

By default, connections will not be closed due to being idle.

§max_pool_size: Option<u32>

The maximum amount of connections that the Client should allow to be created in a connection pool for a given server. If an operation is attempted on a server while max_pool_size connections are checked out, the operation will block until an in-progress operation finishes and its connection is checked back into the pool.

The default value is 100.

§min_pool_size: Option<u32>

The minimum number of connections that should be available in a server’s connection pool at a given time. If fewer than min_pool_size connections are in the pool, connections will be added to the pool in the background until min_pool_size is reached.

The default value is 0.

§read_concern: Option<ReadConcern>

Specifies the default read concern for operations performed on the Client. See the ReadConcern type documentation for more details.

§repl_set_name: Option<String>

The name of the replica set that the Client should connect to.

§retry_reads: Option<bool>

Whether or not the client should retry a read operation if the operation fails.

The default value is true.

§retry_writes: Option<bool>

Whether or not the client should retry a write operation if the operation fails.

The default value is true.

§selection_criteria: Option<SelectionCriteria>

The default selection criteria for operations performed on the Client. See the SelectionCriteria type documentation for more details.

§server_selection_timeout: Option<Duration>

The amount of time the Client should attempt to select a server for an operation before timing outs

The default value is 30 seconds.

§tls: Option<Tls>

The TLS configuration for the Client to use in its connections with the server.

By default, TLS is disabled.

§wait_queue_timeout: Option<Duration>

The amount of time a thread should block while waiting to check out a connection before returning an error. Note that if there are fewer than max_pool_size connections checked out or if a connection is available in the pool, checking out a connection will not block.

By default, threads will wait indefinitely for a connection to become available.

§write_concern: Option<WriteConcern>

Specifies the default write concern for operations performed on the Client. See the WriteConcern type documentation for more details.

Implementations§

Source§

impl ClientOptions

Source

pub fn builder() -> ClientOptionsBuilder<((), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), ())>

Create a builder for building ClientOptions. On the builder, call .hosts(...)(optional), .app_name(...)(optional), .compressors(...)(optional), .cmap_event_handler(...)(optional), .command_event_handler(...)(optional), .connect_timeout(...)(optional), .credential(...)(optional), .direct_connection(...)(optional), .driver_info(...)(optional), .heartbeat_freq(...)(optional), .local_threshold(...)(optional), .max_idle_time(...)(optional), .max_pool_size(...)(optional), .min_pool_size(...)(optional), .read_concern(...)(optional), .repl_set_name(...)(optional), .retry_reads(...)(optional), .retry_writes(...)(optional), .selection_criteria(...)(optional), .server_selection_timeout(...)(optional), .socket_timeout(...)(optional), .tls(...)(optional), .wait_queue_timeout(...)(optional), .write_concern(...)(optional), .zlib_compression(...)(optional), .original_srv_hostname(...)(optional), .original_uri(...)(optional), .resolver_config(...)(optional), .heartbeat_freq_test(...)(optional) to set the values of the fields (they accept Into values). Finally, call .build() to create the instance of ClientOptions.

Source§

impl ClientOptions

Source

pub fn parse(s: &str) -> Result<ClientOptions, Error>

This method will be present if the sync feature is enabled. It’s otherwise identical to the async version

Source

pub fn parse_with_resolver_config( uri: &str, resolver_config: ResolverConfig, ) -> Result<ClientOptions, Error>

This method will be present if the sync feature is enabled. It’s otherwise identical to the async version

Trait Implementations§

Source§

impl Clone for ClientOptions

Source§

fn clone(&self) -> ClientOptions

Returns a duplicate 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 ClientOptions

Source§

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

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

impl Default for ClientOptions

Source§

fn default() -> ClientOptions

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

impl<'de> Deserialize<'de> for ClientOptions

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<ClientOptions, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<ClientOptionsParser> for ClientOptions

Source§

fn from(parser: ClientOptionsParser) -> ClientOptions

Converts to this type from the input type.
Source§

impl PartialEq for ClientOptions

Source§

fn eq(&self, other: &ClientOptions) -> 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.

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

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,