Add the last two docs for Server
This commit is contained in:
parent
7dff9674b6
commit
6b30521c77
34
src/lib.rs
34
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<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 {
|
pub struct Server {
|
||||||
timeout: Duration,
|
timeout: Duration,
|
||||||
complex_body_timeout_override: Option<Duration>,
|
complex_body_timeout_override: Option<Duration>,
|
||||||
|
@ -651,6 +684,7 @@ pub struct Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Server {
|
impl Server {
|
||||||
|
/// Instantiate a new [`Server`] with all the default settings
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
timeout: Duration::from_secs(1),
|
timeout: Duration::from_secs(1),
|
||||||
|
|
Loading…
Reference in a new issue