Struct tokio_jsonrpc::endpoint::Endpoint [] [src]

pub struct Endpoint<Connection, RpcServer> { /* fields omitted */ }

The builder structure for the end point.

This is used to create the endpoint ‒ both the server and client part at once.

Examples

This will create a connection, build a client-only endpoint (eg. the server is dummy) on it and send an RPC to the other side, printing the result once it comes.

let mut core = Core::new().unwrap();
let handle = core.handle();

let request = TcpStream::connect(&"127.0.0.1:2346".parse().unwrap(), &handle)
    .map(move |stream| {
        // Create a client on top of the connection
        let (client, _finished) = Endpoint::client_only(stream.framed(LineCodec::new()))
            .start(&handle);
        // Call a method with some parameters and a 10 seconds timeout
        client.call("request".to_owned(),
                    Some(json!(["param1", "param2"])),
                    Some(Duration::new(10, 0)))
            .and_then(|(_client, future_result)| future_result)
            .map(|response| {
                match response {
                    None => println!("A timeout happened"),
                    Some(Response { result, .. }) => println!("The answer is {:?}", result),
                }
            })
    });

core.run(request).unwrap();

Methods

impl<Connection, RpcServer> Endpoint<Connection, RpcServer> where Connection: Stream<Item=Parsed, Error=IoError>,
        Connection: Sink<SinkItem=Message, SinkError=IoError>,
        Connection: Send + 'static,
        RpcServer: Server + 'static
[src]

Create the endpoint builder.

Pass it the connection to build the endpoint on and the server to use internally.

Set how many RPCs may be process in parallel.

As the RPC may be a future, it is possible to have multiple of them in the pipeline at once. By default, no parallelism is allowed on one endpoint. Calling this sets how many parallel futures there may be at one time on this particular endpoint.

Start the endpoint.

Once all configuration is set, this creates the actual endpoint pair ‒ both the server and the client. It returns the client and a future that resolves once the server terminates. The future yields if there was any error running the server. The server is started on the provided handle. It can be manipulated by the ServerCtl, which is accessible through the returned Client and is passed to each Server callback.

impl<Connection> Endpoint<Connection, EmptyServer> where Connection: Stream<Item=Parsed, Error=IoError>,
        Connection: Sink<SinkItem=Message, SinkError=IoError>,
        Connection: Send + 'static
[src]

Create an endpoint with Empty.

If you want to have client only, you can use this instead of new.

Trait Implementations

impl<Connection: Clone, RpcServer: Clone> Clone for Endpoint<Connection, RpcServer>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<Connection: Debug, RpcServer: Debug> Debug for Endpoint<Connection, RpcServer>
[src]

Formats the value using the given formatter.

impl<Connection: PartialEq, RpcServer: PartialEq> PartialEq for Endpoint<Connection, RpcServer>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<Connection: Hash, RpcServer: Hash> Hash for Endpoint<Connection, RpcServer>
[src]

Feeds this value into the state given, updating the hasher as necessary.

Feeds a slice of this type into the state provided.