We could leverage async in this crate in various ways.
We didn't build this on top of tokio because we wanted to keep the code simple. However, we could optionally add it in one of two ways:
First, the bit that's the same in both of them: add an async Cargo feature that lets you turn async on. That way, without the flag, you get only sync io and little deps, but if you wanted it to be async, you could do so.
Option 1: new method
This option would add an alternate Server, AsyncServer. It would look something like this:
externcrate simple_server;use simple_server::{AsyncServer, ok};fnmain(){let host = "127.0.0.1";let port = "7878";let server = AsycncServer::new(|request,mut response| {ok(response.body("Hello Rust!".as_bytes())?)});
server.listen(host, port);}
Option 2: add futures
Option two is, change the interface of Server to be futures-enabled generally. The futures crate has no dependencies, and so is still pretty small. Then, the switch would only be in the backend, not in the interface.
The tradeoff is basically, with one, we split the "ecosystem", as it were. Option 2 adds a small amount of complexity for the simple case, but unifies everything into one API.
The text was updated successfully, but these errors were encountered:
We could leverage async in this crate in various ways.
We didn't build this on top of tokio because we wanted to keep the code simple. However, we could optionally add it in one of two ways:
First, the bit that's the same in both of them: add an
asyncCargo feature that lets you turn async on. That way, without the flag, you get only sync io and little deps, but if you wanted it to be async, you could do so.Option 1: new method
This option would add an alternate
Server,AsyncServer. It would look something like this:Option 2: add futures
Option two is, change the interface of
Serverto be futures-enabled generally. The futures crate has no dependencies, and so is still pretty small. Then, the switch would only be in the backend, not in the interface.The tradeoff is basically, with one, we split the "ecosystem", as it were. Option 2 adds a small amount of complexity for the simple case, but unifies everything into one API.
The text was updated successfully, but these errors were encountered: