pub struct HttpServer { /* private fields */ }
Expand description
HTTP Server
Represents an HTTP Server, bound to a TCP Port
§Example
use http_srv::HttpServer;
use http_srv::ServerConfig;
use http_srv::handler::Handler;
use http_srv::request::HttpRequest;
let config = ServerConfig::default();
let mut server = HttpServer::new(config).unwrap();
let mut handler = Handler::new();
handler.get("/", |req: &mut HttpRequest| {
req.ok()
});
server.set_handler(handler);
server.run();
Implementations§
Source§impl HttpServer
impl HttpServer
Sourcepub fn new(config: ServerConfig) -> Result<Self>
pub fn new(config: ServerConfig) -> Result<Self>
Create a new HTTP Server
§Errors
- If the server fails to bind to the TCP port
- If the thread pool fails to initialize
Trait Implementations§
Source§impl Default for HttpServer
impl Default for HttpServer
Source§fn default() -> Self
fn default() -> Self
Default Server
- Configuration:
ServerConfig::default
- Handler:
Handler::default
§Panics
If the HttpServer
fails to initialize
Auto Trait Implementations§
impl Freeze for HttpServer
impl !RefUnwindSafe for HttpServer
impl Send for HttpServer
impl Sync for HttpServer
impl Unpin for HttpServer
impl !UnwindSafe for HttpServer
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