pub struct Config {
pub max: usize,
pub start: usize,
pub step: usize,
}Expand description
The configuration options of the pools internal store.
The settings always apply to a specific type of object beeing stored in the pool, and never at the pool as a whole. That is if you store e.g. 2 different object types and configure a default maximum capacity of 1_000, the pool will store up to 2_000 objects. The settings are intended for limiting the memory usage of the pool.
The pools fallback configuration will apply to all object types until you set a custom one for an object type.
If you do not specify a costum fallback config for the pool, the pool will use the default values for Config.
We allow setting a max capacity of the internal pool buffer. If the buffer is full
and another object gets added to the pool, the new object will get dropped.
If a certain buffer gets created, it will use the start value to configure its
initial capacity. Whenever the capacity is reached and its length has not yet reached the
max value, the step value is used to determine by which amount
the capacity should be increased. Note that it will use a lower value then step
if otherwise the capacity would exceed the max value.
§Example
use generic_pool::{Pool, Config};
fn main() {
// Use a non-default config.
let config = Config {
max: 1_000,
step: 100,
start: 500,
};
assert_ne!(config, Config::default());
let mut pool = Pool::with_fallback_config(config); // NOTE Config implements Copy.
// Alternative:
// let mut pool = Pool::new();
// pool.set_fallback_config(config);
assert_eq!(config, pool.fallback_config());
assert_eq!(config, pool.get_config::<Vec<u8>>());
// Create a costum config for `Vec<u8>`.
let custom_config = Config {
max: 100,
step: 10,
start: 10,
};
pool.set_config::<Vec<u8>>(custom_config);
assert_eq!(custom_config, pool.get_config::<Vec<u8>>());
}Fields§
§max: usizeThe maximum number of elements of a specific type to be hold inside the pool.
Default: 100_000
start: usizeThe initial capacity for the storage of elements of a specific type.
Default: 1_000
step: usizeHow much capacity to add to the storage of elements of a specific type if the storage is full and has not yet reached the maximum.
Default: 1_000