[−][src]Struct mini_async_http::AIOServer
Main struct of the crate, represent the http server
Implementations
impl<H> AIOServer<H> where
H: Send + Sync + 'static + Fn(&Request) -> Response,
[src]
H: Send + Sync + 'static + Fn(&Request) -> Response,
pub fn new(size: i32, addr: &str, handler: H) -> AIOServer<H>
[src]
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() });
pub fn start(&mut self)
[src]
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();
impl<H> AIOServer<H>
[src]
pub fn handle(&self) -> ServerHandle
[src]
Get a ServerHandle
to this server
Trait Implementations
Auto Trait Implementations
impl<H> !RefUnwindSafe for AIOServer<H>
impl<H> Send for AIOServer<H> where
H: Send + Sync,
H: Send + Sync,
impl<H> !Sync for AIOServer<H>
impl<H> Unpin for AIOServer<H>
impl<H> !UnwindSafe for AIOServer<H>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,