This library provides a way easily to implement Connection Pools for any [thrift::TThriftClient
],
which can then be used alongside [bb8
] and/or [r2d2
]
There are 2 possible use cases
If you're implementing a library that provides a (possibly generated) thrift client,
you should implement the [ThriftConnection
] and [FromProtocol
] traits
for that client
```rust
// A typical generated client looks like this
struct MyThriftClient
impl
type OutputProtocol = Op;
fn from_protocol(
input_protocol: Self::InputProtocol,
output_protocol: Self::OutputProtocol,
) -> Self {
MyThriftClient {
i_prot: input_protocol,
o_prot: output_protocol,
}
}
}
impl
```
If you're implementing an application that uses a (possibly generated) thrift client that
implements [FromProtocol
] and [ThriftConnection
] (see previous section), you can use
[r2d2
] or [bb8
] (make sure to read their documentations) along with
[ThriftConnectionManager
] to create Connection Pools for the client
```rust should_panic
#
#
#
#
#
#
type Client = MyThriftClient<
TCompactInputProtocol
;
// create a connection manager
let manager = MakeThriftConnectionFromAddrs::
// we're able to create bb8 and r2d2 Connection Pools let bb8 = bb8::Pool::builder().build(manager.clone()).await?; let r2d2 = r2d2::Pool::builder().build(manager)?;
// get a connection let conn1 = bb8.get().await?; let conn2 = r2d2.get()?;
```