Add the last two docs for Server

This commit is contained in:
Emi Tatsuo 2020-12-07 16:46:13 -05:00
parent 7dff9674b6
commit 6b30521c77
Signed by: Emi
GPG key ID: 68FAB2E2E6DFC98B

View file

@ -631,6 +631,39 @@ impl std::error::Error for ParseError {
}
}
/// A builder for configuring a kochab server
///
/// Once created with [`Server::new()`], different configuration methods can be
/// called to set up the server, before finally making a call to [`serve_ip()`] or
/// [`serve_unix()`].
///
/// Technically, no methods need to be called in order to create the server, but unless
/// you add at least one route with [`add_route()`], the server will respond with `51 NOT
/// FOUND` to all requests.
///
/// # Example
/// ```no_run
/// use anyhow::Result;
/// # use kochab::Response;
/// # use kochab::Request;
/// # use kochab::Server;
///
/// #[tokio::main]
/// async fn main() {
/// Server::new()
/// .add_route("/", hello_world)
/// .serve_ip("localhost:1965")
/// .await;
/// }
///
/// async fn hello_world(_: Request) -> Result<Response> {
/// Ok(Response::success_gemini("Hello world!"))
/// }
/// ```
///
/// [`serve_ip()`]: Self::serve_ip()
/// [`serve_unix()`]: Self::serve_unix()
/// [`add_route()`]: Self::add_route()
pub struct Server {
timeout: Duration,
complex_body_timeout_override: Option<Duration>,
@ -651,6 +684,7 @@ pub struct Server {
}
impl Server {
/// Instantiate a new [`Server`] with all the default settings
pub fn new() -> Self {
Self {
timeout: Duration::from_secs(1),