pub struct Server<T, const STACK_SIZE: usize = 65536> { /* private fields */ }Expand description
A HTTP server
Implementations§
source§impl<T, const STACK_SIZE: usize> Server<T, STACK_SIZE>
impl<T, const STACK_SIZE: usize> Server<T, STACK_SIZE>
sourcepub fn new(worker_max: usize, handler: T) -> Self
pub fn new(worker_max: usize, handler: T) -> Self
Creates a new server bound on the given address
Examples found in repository?
examples/helloworld.rs (line 15)
6 7 8 9 10 11 12 13 14 15 16 17
fn main() {
// Define our request handler
let request_handler = |_: Request| {
let mut response = Response::new_200_ok();
response.set_body_data(b"Hello world\r\n");
response
};
// Create a server that listens at [::]:9999 with up to 2048 worker threads under load if necessary
let server: Server<_> = Server::new(2048, request_handler);
server.accept("[::]:9999").expect("server failed");
}More examples
examples/helloworld-nokeepalive.rs (line 16)
6 7 8 9 10 11 12 13 14 15 16 17 18
fn main() {
// Define our request handler
let request_handler = |_: Request| {
let mut response = Response::new_200_ok();
response.set_body_data(b"Hello World\r\n");
response.set_connection_close();
response
};
// Create a server that listens at [::]:9999 with up to 2048 worker threads under load if necessary
let server: Server<_> = Server::new(2048, request_handler);
server.accept("[::]:9999").expect("server failed");
}examples/teapot.rs (line 21)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() {
// Define our request handler
let request_handler = |request: Request| {
// Create the response body
let mut message = b"There are only teapots in ".to_vec();
message.extend_from_slice(&request.target);
message.extend_from_slice(b"\r\n");
// Send the response
let mut response = Response::new_status_reason(418, "I'm a teapot");
response.set_body_data(message);
response
};
// Create a server that listens at [::]:9999 with up to 2048 worker threads under load if necessary
let server: Server<_> = Server::new(2048, request_handler);
server.accept("[::]:9999").expect("server failed");
}sourcepub fn accept<A>(self, address: A) -> Result<Infallible, Error>where
A: ToSocketAddrs,
pub fn accept<A>(self, address: A) -> Result<Infallible, Error>where
A: ToSocketAddrs,
Listens on the given address and accepts forever
Examples found in repository?
examples/helloworld.rs (line 16)
6 7 8 9 10 11 12 13 14 15 16 17
fn main() {
// Define our request handler
let request_handler = |_: Request| {
let mut response = Response::new_200_ok();
response.set_body_data(b"Hello world\r\n");
response
};
// Create a server that listens at [::]:9999 with up to 2048 worker threads under load if necessary
let server: Server<_> = Server::new(2048, request_handler);
server.accept("[::]:9999").expect("server failed");
}More examples
examples/helloworld-nokeepalive.rs (line 17)
6 7 8 9 10 11 12 13 14 15 16 17 18
fn main() {
// Define our request handler
let request_handler = |_: Request| {
let mut response = Response::new_200_ok();
response.set_body_data(b"Hello World\r\n");
response.set_connection_close();
response
};
// Create a server that listens at [::]:9999 with up to 2048 worker threads under load if necessary
let server: Server<_> = Server::new(2048, request_handler);
server.accept("[::]:9999").expect("server failed");
}examples/teapot.rs (line 22)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() {
// Define our request handler
let request_handler = |request: Request| {
// Create the response body
let mut message = b"There are only teapots in ".to_vec();
message.extend_from_slice(&request.target);
message.extend_from_slice(b"\r\n");
// Send the response
let mut response = Response::new_status_reason(418, "I'm a teapot");
response.set_body_data(message);
response
};
// Create a server that listens at [::]:9999 with up to 2048 worker threads under load if necessary
let server: Server<_> = Server::new(2048, request_handler);
server.accept("[::]:9999").expect("server failed");
}Auto Trait Implementations§
impl<T, const STACK_SIZE: usize> RefUnwindSafe for Server<T, STACK_SIZE>where
T: RefUnwindSafe,
impl<T, const STACK_SIZE: usize> Send for Server<T, STACK_SIZE>where
T: Send,
impl<T, const STACK_SIZE: usize> Sync for Server<T, STACK_SIZE>
impl<T, const STACK_SIZE: usize> Unpin for Server<T, STACK_SIZE>where
T: Unpin,
impl<T, const STACK_SIZE: usize> UnwindSafe for Server<T, STACK_SIZE>where
T: UnwindSafe,
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