Thrift Pool

This library provides a simple way implement bb8 and/or r2d2 Connection Pools for any TThriftClient

Documenation

```rust use thrift::protocol::{TCompactInputProtocol, TCompactOutputProtocol, TInputProtocol, TOutputProtocol}; use thrift::transport::{ ReadHalf, TFramedReadTransport, TFramedWriteTransport, TTcpChannel, WriteHalf, }; use thrift_pool::{MakeThriftConnectionFromAddrs, ThriftConnectionManager, ThriftConnection, FromProtocol};

// A typical generated client struct MyThriftClient { iprot: Ip, oprot: Op, }

// implement this trait so that MakeThriftConnectionFromAddrs can create it impl FromProtocol for MyThriftClient { type InputProtocol = Ip;

type OutputProtocol = Op;

fn from_protocol(
    input_protocol: Self::InputProtocol,
    output_protocol: Self::OutputProtocol,
) -> Self {
    MyThriftClient {
        i_prot: input_protocol,
        o_prot: output_protocol,
    }
}

}

// implement this trait so that ThriftConnectionManager can manage it impl ThriftConnection for MyThriftClient { type Error = thrift::Error; fn isvalid(&mut self) -> Result<(), Self::Error> { Ok(()) } fn hasbroken(&mut self) -> bool { false } }

// the actual connection type type Client = MyThriftClient< TCompactInputProtocol>>, TCompactOutputProtocol>>,

;

// this works because we implemented FromProtocol for the client // AND // because the Protocol and Transport types used here satisfy the contraints let manager = ThriftConnectionManager::new( MakeThriftConnectionFromAddrs::::new("localhost:9090") );

// this works because we implemented ThriftConnection for the client let pool = r2d2::Pool::builder().build(manager)?;

// this also works after enabling the impl-bb8 feature let pool = bb8::Pool::builder().build(manager).await?;

// the pool can be used just like in r2d2/bb8 documentation let mut client = pool.get()?; ```

Examples