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]
Connection: Sink<SinkItem=Message, SinkError=IoError>,
Connection: Send + 'static,
RpcServer: Server + 'static
fn new(connection: Connection, server: RpcServer) -> Self
Create the endpoint builder.
Pass it the connection to build the endpoint on and the server to use internally.
fn parallel(self, parallel: usize) -> Self
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.
fn logger(self, logger: Logger) -> Self
Sets the logger used by the endpoint.
By default, nothing is logged anywhere. But if you specify a logger, it'll be used for logging various messages. The logger is used verbatim ‒ if you want the endpoint to use a child logger, inherit it on your side.
fn start(self, handle: &Handle) -> (Client, Box<Future<Item=(), Error=IoError>>)
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]
Connection: Sink<SinkItem=Message, SinkError=IoError>,
Connection: Send + 'static
fn client_only(connection: Connection) -> Self
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]
fn clone(&self) -> Endpoint<Connection, RpcServer>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more