fastdfs 0.1.1

Rust client for FastDFS distributed file system
Documentation
#![allow(dead_code)]

use std::time::Duration;

#[derive(Copy, Clone)]
pub struct PoolConfig {
    pub max_total_per_key: usize,
    pub max_wait: Option<Duration>,
    pub test_on_borrow: bool,
    pub test_on_return: bool,
    pub test_while_idle: bool,
    pub test_timeout: Duration,
    /// Sets the duration to sleep between runs of the idle object evictor thread.
    pub time_between_eviction_runs: Duration,
    /// Sets the minimum amount of time an object may sit idle in the pool before it is eligible for eviction by the idle object evictor
    pub min_evictable_idle_duration: Duration,
    /// Set the maximum lifetime of individual object.
    ///
    /// Any object with a lifetime greater than this will be destroyed.
    pub max_lifetime: Duration,
    /// Set a maximum idle duration for individual object.
    ///
    /// Any object that remains in the idle queue longer than this will be destroyed.
    pub idle_timeout: Duration,
    ///  Gets whether the pool has LIFO (last in, first out) behavior with
    /// respect to idle objects - always returning the most recently used object
    /// from the pool, or as a FIFO (first in, first out) queue, where the pool
    /// always returns the oldest object in the idle object pool.
    pub lifo: bool,
}

impl Default for PoolConfig {
    fn default() -> Self {
        Self {
            max_total_per_key: 50,
            max_wait: None,
            test_on_borrow: false,
            test_on_return: false,
            test_while_idle: true,
            test_timeout: Duration::from_secs(3),
            time_between_eviction_runs: Duration::from_secs(2 * 60),
            min_evictable_idle_duration: Duration::from_secs(15),
            max_lifetime: Duration::MAX,
            idle_timeout: Duration::MAX,
            lifo: true,
        }
    }
}

impl PoolConfig {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn max_total_per_key(mut self, max_total_per_key: usize) -> Self {
        self.max_total_per_key = max_total_per_key;
        self
    }

    pub fn max_wait(mut self, max_wait: Option<Duration>) -> Self {
        self.max_wait = max_wait;
        self
    }

    pub fn test_on_borrow(mut self, test_on_borrow: bool) -> Self {
        self.test_on_borrow = test_on_borrow;
        self
    }

    pub fn test_on_return(mut self, test_on_return: bool) -> Self {
        self.test_on_return = test_on_return;
        self
    }

    pub fn test_while_idle(mut self, test_while_idle: bool) -> Self {
        self.test_while_idle = test_while_idle;
        self
    }

    pub fn test_timeout(mut self, test_timeout: Duration) -> Self {
        self.test_timeout = test_timeout;
        self
    }

    pub fn time_between_eviction_runs(mut self, time_between_eviction_runs: Duration) -> Self {
        self.time_between_eviction_runs = time_between_eviction_runs;
        self
    }

    pub fn min_evictable_idle_duration(mut self, min_evictable_idle_duration: Duration) -> Self {
        self.min_evictable_idle_duration = min_evictable_idle_duration;
        self
    }

    pub fn max_lifetime(mut self, max_lifetime: Duration) -> Self {
        self.max_lifetime = max_lifetime;
        self
    }

    pub fn idle_timeout(mut self, idle_timeout: Duration) -> Self {
        self.idle_timeout = idle_timeout;
        self
    }

    pub fn lifo(mut self, lifo: bool) -> Self {
        self.lifo = lifo;
        self
    }
}