Skip to main content

Configurable

Trait Configurable 

Source
pub trait Configurable: Pool {
    type Options: Send;

    // Required method
    fn init_with<'life0, 'async_trait, F>(
        figment: &'life0 Figment,
        f: F,
    ) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>
       where F: FnOnce(&Config, Self::Options) -> Result<Self::Options, Self::Error> + Send + 'async_trait,
             Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

A Pool that supports customization during initialization.

This trait enables Database::custom() and Database::try_custom(). It is implemented for SQLx pools and MongoDB clients.

Required Associated Types§

Source

type Options: Send

The driver’s configuration options.

The configuration types for the supported drivers are:

  • SQLx: (sqlx::pool::PoolOptions<D>, ConnectOptions), where D is Sqlite, Postgres, or MySql, and ConnectOptions is SqliteConnectOptions, PgConnectOptions, or MySqlConnectOptions, respectively.
  • MongoDB: mongodb::options::ClientOptions.

Required Methods§

Source

fn init_with<'life0, 'async_trait, F>( figment: &'life0 Figment, f: F, ) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>
where F: FnOnce(&Config, Self::Options) -> Result<Self::Options, Self::Error> + Send + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Constructs a pool from figment, customizing its options with f.

Implementations should extract Config from figment and apply its values and the driver’s defaults to Self::Options. The function f is then called with the configuration and options. The returned options are used to create the pool.

Implementations should share this initialization path with Pool::init(). Any error returned by f is returned to the caller.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Configurable for Client

Source§

type Options = ClientOptions

Source§

fn init_with<'life0, 'async_trait, F>( figment: &'life0 Figment, f: F, ) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>
where F: FnOnce(&Config, Self::Options) -> Result<Self::Options, Self::Error> + Send + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Source§

impl<D: Database> Configurable for Pool<D>

Source§

type Options = (PoolOptions<D>, <<D as Database>::Connection as Connection>::Options)

Source§

fn init_with<'life0, 'async_trait, F>( figment: &'life0 Figment, f: F, ) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>
where F: FnOnce(&Config, Self::Options) -> Result<Self::Options, Self::Error> + Send + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Implementors§