Struct thrift_pool::MakeThriftConnectionFromAddrs[][src]

pub struct MakeThriftConnectionFromAddrs<T, S> { /* fields omitted */ }
Expand description

A MakeThriftConnection that attempts to create new connections from a ToSocketAddrs and a FromProtocol

The connection is accordance with the thrift rust tutorial:

  • Open a TTcpChannel
  • Split it
  • Create TReadTransport and TWriteTransport
  • Create TInputProtocol and TOutputProtocol
  • Create a client with i_prot and o_prot

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

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The error type returned when a connection creation fails

The connection type the we are trying to create

Attempt to create a new connection

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.