mirror of
https://github.com/OMGeeky/tarpc.git
synced 2026-01-03 18:08:51 +01:00
main to use a struct Foo
Shows a more complete example
This commit is contained in:
@@ -5,16 +5,21 @@ extern crate byteorder;
|
||||
|
||||
use std::net::{TcpListener, TcpStream};
|
||||
|
||||
#[derive(Debug, RustcEncodable, RustcDecodable)]
|
||||
pub struct Foo {
|
||||
message: String
|
||||
}
|
||||
|
||||
rpc_service!(my_server:
|
||||
hello(String) -> String;
|
||||
hello(::Foo) -> ::Foo;
|
||||
add((i32, i32)) -> i32;
|
||||
);
|
||||
|
||||
use my_server::*;
|
||||
|
||||
impl Service for () {
|
||||
fn hello(&self, s: String) -> String {
|
||||
format!("Hello, {}", s)
|
||||
fn hello(&self, s: Foo) -> Foo {
|
||||
Foo{message: format!("Hello, {}", &s.message)}
|
||||
}
|
||||
|
||||
fn add(&self, (x, y): (i32, i32)) -> i32 {
|
||||
@@ -33,5 +38,5 @@ fn main() {
|
||||
let mut client = Client(TcpStream::connect("127.0.0.1:9000").unwrap());
|
||||
println!("Client running");
|
||||
println!("add((1, 2)) => {}", client.add((1, 2)).unwrap());
|
||||
println!("hello(\"adam\") => {:?}", client.hello("Adam".into()));
|
||||
println!("hello(\"adam\") => {:?}", client.hello(Foo{message: "Adam".into()}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user