Add service name to generated items.

With this change, the service definitions don't need to be isolated in their own modules.
This commit is contained in:
Tim Kuehn
2019-07-23 01:47:14 -07:00
parent 5c485fe608
commit 2f24842b2d
10 changed files with 167 additions and 124 deletions

View File

@@ -17,12 +17,12 @@ use tarpc::{
server::{self, Channel, Handler},
};
// This is the type that implements the generated Service trait. It is the business logic
// This is the type that implements the generated World trait. It is the business logic
// and is used to start the server.
#[derive(Clone)]
struct HelloServer(SocketAddr);
impl service::Service for HelloServer {
impl service::World for HelloServer {
// Each defined rpc generates two items in the trait, a fn that serves the RPC, and
// an associated type representing the future output by the fn.
@@ -70,11 +70,11 @@ async fn main() -> io::Result<()> {
.map(server::BaseChannel::with_defaults)
// Limit channels to 1 per IP.
.max_channels_per_key(1, |t| t.as_ref().peer_addr().unwrap().ip())
// serve is generated by the service! macro. It takes as input any type implementing
// the generated Service trait.
// serve is generated by the service attribute. It takes as input any type implementing
// the generated World trait.
.map(|channel| {
let server = HelloServer(channel.as_ref().as_ref().peer_addr().unwrap());
channel.respond_with(service::serve(server))
channel.respond_with(service::serve_world(server))
})
// Max 10 channels.
.buffer_unordered(10)