From 6b30521c7706365c478ae1faae90abc2c8f87b34 Mon Sep 17 00:00:00 2001 From: Emi Tatsuo Date: Mon, 7 Dec 2020 16:46:13 -0500 Subject: [PATCH] Add the last two docs for Server --- src/lib.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index d12e448..5039e39 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 { +/// 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, @@ -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),