pub struct Config {
pub addr: Option<String>,
pub pool: Option<PoolConfig>,
}Expand description
Configuration object.
§Example (from environment)
You can read the configuration using the
config crate as following:
MEMCACHED__ADDR=127.0.0.1:11211
MEMCACHED__POOL__MAX_SIZE=16
MEMCACHED__POOL__TIMEOUTS__WAIT__SECS=5
MEMCACHED__POOL__TIMEOUTS__WAIT__NANOS=0ⓘ
#[derive(serde::Deserialize, serde::Serialize)]
struct Config {
memcached: deadpool_memcached::Config,
}
impl Config {
pub fn from_env() -> Result<Self, config::ConfigError> {
let mut cfg = config::Config::builder()
.add_source(config::Environment::default().separator("__"))
.build()?;
cfg.try_deserialize()
}
}Fields§
§addr: Option<String>Memcached address.
pool: Option<PoolConfig>Pool configuration.
Implementations§
Source§impl Config
impl Config
Sourcepub fn new(addr: impl Into<String>) -> Self
pub fn new(addr: impl Into<String>) -> Self
Creates a new Config with the given Memcached address.
Sourcepub fn create_pool(
&self,
runtime: Option<Runtime>,
) -> Result<Pool, CreatePoolError>
pub fn create_pool( &self, runtime: Option<Runtime>, ) -> Result<Pool, CreatePoolError>
Creates a new Pool using this Config.
A Runtime is required if any Timeouts are configured on the
PoolConfig (wait, create or recycle). Pass None if you do
not need timeouts.
§Errors
See CreatePoolError for details.
Sourcepub fn builder(&self) -> Result<PoolBuilder, ConfigError>
pub fn builder(&self) -> Result<PoolBuilder, ConfigError>
Sourcepub fn get_pool_config(&self) -> PoolConfig
pub fn get_pool_config(&self) -> PoolConfig
Returns deadpool::managed::PoolConfig which can be used to construct
a deadpool::managed::Pool instance.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more