Skip to content

Conversation

@willcrichton
Copy link
Contributor

@willcrichton willcrichton commented Jul 30, 2024

Change the miniserve API to use Rust's async features via Tokio. Unfortunately, this breaks the server crate, so CI is failing. Help me finish the port.

pub trait Handler: Fn(Request) -> Response + Send + Sync + 'static {}
pub trait Handler: Fn(Request) -> Self::Future + Send + Sync + 'static {
type Future: Future<Output = Response> + Send + Sync + 'static;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a close look at the change to the Handler trait. Previously, a handler was a function that took a request and returned a response. Now, a handler is a function that takes a request and returns a future which eventually returns a response.

pub fn run(self) {
let listener =
TcpListener::bind("127.0.0.1:3000").expect("Failed to connect to 127.0.0.1:3000");
pub async fn run(self) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the run function is now asynchronous, indicated by the async keyword.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants