main to use a struct Foo

Shows a more complete example
This commit is contained in:
Adam Wright
2016-01-08 03:01:07 -08:00
parent 78d04acaa4
commit 4987fd9759

View File

@@ -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()}));
}