pub struct MakeThriftConnectionFromAddrs<T, S> { /* private fields */ }Expand description
A MakeThriftConnection that attempts to create new connections
from a ToSocketAddrs and a FromProtocol
The connection is created in accordance with the thrift rust tutorial:
- Open a
TTcpChanneland split it - Use the created
[ReadHalf]and[WriteHalf]to createTReadTransportandTWriteTransport - Use those to create
TInputProtocolandTOutputProtocol - Create a new client with
i_protando_prot– It needs to implementFromProtocol
For that to happen, T needs to be able
to create the Read/Write Transports
and Input/Output Protocols from
the ReadHalf and WriteHalf of the TTcpChannel.
Those contraints should be fairly easily satisfied
by implementing the relevant traits in the library
use thrift_pool::{MakeThriftConnectionFromAddrs, FromProtocol};
use thrift::{
protocol::{TCompactInputProtocol, TCompactOutputProtocol, TInputProtocol, TOutputProtocol},
transport::{
ReadHalf, TFramedReadTransport, TFramedWriteTransport, TIoChannel, TReadTransport,
TTcpChannel, TWriteTransport, WriteHalf,
},
};
// A typical generated client looks like this
struct MyThriftClient<Ip: TInputProtocol, Op: TOutputProtocol> {
i_prot: Ip,
o_prot: Op,
}
impl<Ip: TInputProtocol, Op: TOutputProtocol> FromProtocol for MyThriftClient<Ip, Op> {
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,
}
}
}
type Client = MyThriftClient<
TCompactInputProtocol<TFramedReadTransport<ReadHalf<TTcpChannel>>>,
TCompactOutputProtocol<TFramedWriteTransport<WriteHalf<TTcpChannel>>>,
>;
// The Protocols/Transports used in this client implement the necessary traits so we can do this
let manager =
MakeThriftConnectionFromAddrs::<Client, _>::new("localhost:9090").into_connection_manager();
Implementations§
Source§impl<T, S> MakeThriftConnectionFromAddrs<T, S>
impl<T, S> MakeThriftConnectionFromAddrs<T, S>
Source§impl<S: ToSocketAddrs + Clone, RT: FromRead<Read = ReadHalf<TTcpChannel>>, IP: FromReadTransport<ReadTransport = RT>, WT: FromWrite<Write = WriteHalf<TTcpChannel>>, OP: FromWriteTransport<WriteTransport = WT>, T: FromProtocol<InputProtocol = IP, OutputProtocol = OP>> MakeThriftConnectionFromAddrs<T, S>
impl<S: ToSocketAddrs + Clone, RT: FromRead<Read = ReadHalf<TTcpChannel>>, IP: FromReadTransport<ReadTransport = RT>, WT: FromWrite<Write = WriteHalf<TTcpChannel>>, OP: FromWriteTransport<WriteTransport = WT>, T: FromProtocol<InputProtocol = IP, OutputProtocol = OP>> MakeThriftConnectionFromAddrs<T, S>
pub fn into_connection_manager(self) -> ThriftConnectionManager<Self>
Trait Implementations§
Source§impl<T, S: Clone> Clone for MakeThriftConnectionFromAddrs<T, S>
impl<T, S: Clone> Clone for MakeThriftConnectionFromAddrs<T, S>
Source§impl<T, S: Debug> Debug for MakeThriftConnectionFromAddrs<T, S>
impl<T, S: Debug> Debug for MakeThriftConnectionFromAddrs<T, S>
Source§impl<S: ToSocketAddrs + Clone, RT: FromRead<Read = ReadHalf<TTcpChannel>>, IP: FromReadTransport<ReadTransport = RT>, WT: FromWrite<Write = WriteHalf<TTcpChannel>>, OP: FromWriteTransport<WriteTransport = WT>, T: FromProtocol<InputProtocol = IP, OutputProtocol = OP>> MakeThriftConnection for MakeThriftConnectionFromAddrs<T, S>
impl<S: ToSocketAddrs + Clone, RT: FromRead<Read = ReadHalf<TTcpChannel>>, IP: FromReadTransport<ReadTransport = RT>, WT: FromWrite<Write = WriteHalf<TTcpChannel>>, OP: FromWriteTransport<WriteTransport = WT>, T: FromProtocol<InputProtocol = IP, OutputProtocol = OP>> MakeThriftConnection for MakeThriftConnectionFromAddrs<T, S>
Auto Trait Implementations§
impl<T, S> Freeze for MakeThriftConnectionFromAddrs<T, S>where
S: Freeze,
impl<T, S> RefUnwindSafe for MakeThriftConnectionFromAddrs<T, S>where
S: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, S> Send for MakeThriftConnectionFromAddrs<T, S>
impl<T, S> Sync for MakeThriftConnectionFromAddrs<T, S>
impl<T, S> Unpin for MakeThriftConnectionFromAddrs<T, S>
impl<T, S> UnwindSafe for MakeThriftConnectionFromAddrs<T, S>where
S: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more