Trait tourniquet::Connector[][src]

pub trait Connector<SvcSrc, Svc, E> {
    fn connect<'life0, 'life1, 'async_trait>(
        &'life0 self,
        src: &'life1 SvcSrc
    ) -> Pin<Box<dyn Future<Output = Result<Svc, E>> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
; }
Expand description

Trait to be implemented by connector types. Used to get a connected service from its connection information.

Note that the implementor type can hold data for connection information shared across all providers, like TLS certificates, port, database name, …

Example

use std::{io::Error, net::IpAddr};
use tokio::net::TcpStream;
use tourniquet::Connector;

struct Conn(u16);

#[async_trait]
impl Connector<IpAddr, Mutex<TcpStream>, Error> for Conn {
    async fn connect(&self, src: &IpAddr) -> Result<Mutex<TcpStream>, Error> {
        let Conn(ref port) = self;
        TcpStream::connect((*src, *port)).await.map(Mutex::new)
    }
}

Required methods

Implementors