use std::time::{Duration, Instant};
use future::{self, BoxFuture};
use futures::prelude::*;
use crate::{error::Error, Ping, PingState, Poolable};
pub trait ConnectionFactory {
type Connection: Poolable;
fn create_connection(&self) -> BoxFuture<Result<Self::Connection, Error>>;
fn connecting_to(&self) -> &str;
fn ping(&self, _timeout: Instant) -> BoxFuture<Ping> {
future::ready(Ping {
connect_time: None,
latency: None,
total_time: Duration::default(),
uri: self.connecting_to().to_owned(),
state: PingState::failed_msg("pinging is not supported by this connection factory"),
})
.boxed()
}
}