From 80d49d8ca57d9807e656e46d275379c80d14f06b Mon Sep 17 00:00:00 2001 From: Alec Thilenius Date: Thu, 28 Dec 2023 11:52:42 -0500 Subject: [PATCH] Update readme. --- README.md | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 2774cd4..d654e44 100644 --- a/README.md +++ b/README.md @@ -109,10 +109,9 @@ fn main() { With the boring stuff out of the way, let's implement our service using Axum! ```rust -use std::net::SocketAddr; - +use async_stream::stream; use axum::{extract::Host, Router}; -use axum_connect::prelude::*; +use axum_connect::{futures::Stream, prelude::*}; use proto::hello::*; mod proto { @@ -123,19 +122,18 @@ mod proto { #[tokio::main] async fn main() { - // Build our application with a route. Note the `rpc` method which was added - // by `axum-connect`. It expect a service method handler, wrapped in it's - // respective type. The handler (below) is just a normal Rust function. Just - // like Axum, it also supports extractors! - let app = Router::new().rpc(HelloWorldService::say_hello(say_hello_success)); + // Build our application with a route. Note the `rpc` method which was added by `axum-connect`. + // It expect a service method handler, wrapped in it's respective type. The handler (below) is + // just a normal Rust function. Just like Axum, it also supports extractors! + let app = Router::new() + .rpc(HelloWorldService::say_hello(say_hello_success)) + .rpc(HelloWorldService::say_hello_stream(say_hello_stream)); - // Axum boilerplate to start the server. - let addr = SocketAddr::from(([127, 0, 0, 1], 3030)); - println!("listening on http://{}", addr); - axum::Server::bind(&addr) - .serve(app.into_make_service()) + let listener = tokio::net::TcpListener::bind("127.0.0.1:3030") .await .unwrap(); + println!("listening on http://{:?}", listener.local_addr()); + axum::serve(listener, app).await.unwrap(); } async fn say_hello_success(