pub struct AIOServer<H> { /* private fields */ }
Expand description
Main struct of the crate, represent the http server
Implementations§
Source§impl<H> AIOServer<H>
impl<H> AIOServer<H>
Sourcepub fn new(size: i32, addr: &str, handler: H) -> AIOServer<H>
pub fn new(size: i32, addr: &str, handler: H) -> AIOServer<H>
Start the server with the given thread pool size and bind to the given address The given function is executed for each http request received
§Argument
size
- Number of thread that will be spawned minimum is 1. The total minimum number of thread is 2 : 1 to handle request and 1 to run the event loopaddr
- Address the server will bind to. The format is the same as std::net::TcpListener. If the address is incorrect or cannot be bound to, the function will panichandler
- function executed for each received http request
§Example
Create a simple server that will respond with a HTTP response with status 200, content type header “text/plain” and body “Hello”
let server = mini_async_http::AIOServer::new(3, "0.0.0.0:7878", move |request|{
mini_async_http::ResponseBuilder::empty_200()
.body(b"Hello")
.content_type("text/plain")
.build()
.unwrap()
});
Sourcepub fn start(&mut self)
pub fn start(&mut self)
Start the event loop. This call is blocking but you can still interact with the server through the Handle
§Example
Create a simple server and then start it. It is started from another thread as the start call is blocking. After spawning the thread, wait for the server to be ready and then shut it down
let mut server = mini_async_http::AIOServer::new(3, "0.0.0.0:7879", move |request|{
mini_async_http::ResponseBuilder::empty_200()
.body(b"Hello")
.content_type("text/plain")
.build()
.unwrap()
});
let handle = server.handle();
std::thread::spawn(move || {
server.start();
});
handle.ready();
handle.shutdown();
Source§impl<H> AIOServer<H>
impl<H> AIOServer<H>
Sourcepub fn handle(&self) -> ServerHandle
pub fn handle(&self) -> ServerHandle
Get a ServerHandle
to this server
Trait Implementations§
Auto Trait Implementations§
impl<H> !Freeze for AIOServer<H>
impl<H> !RefUnwindSafe for AIOServer<H>
impl<H> Send for AIOServer<H>
impl<H> !Sync for AIOServer<H>
impl<H> Unpin for AIOServer<H>
impl<H> !UnwindSafe for AIOServer<H>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more