From 1766ab4c9ce37f81859aafa85ee64a5add36c2bb Mon Sep 17 00:00:00 2001 From: Emii Tatsuo Date: Wed, 25 Nov 2020 15:52:44 -0500 Subject: [PATCH] Merge `Builder` and `Server` in the public API into one concept --- src/handling.rs | 2 +- src/lib.rs | 16 ++++++---------- src/types/request.rs | 2 +- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/handling.rs b/src/handling.rs index 6f747b9..f869605 100644 --- a/src/handling.rs +++ b/src/handling.rs @@ -26,7 +26,7 @@ use crate::{Document, types::{Body, Response, Request}}; /// /// The most useful part of the documentation for this is the implementations of [`From`] /// on it, as this is what can be passed to -/// [`Builder::add_route`](crate::Builder::add_route) in order to create a new route. +/// [`Server::add_route()`](crate::Server::add_route()) in order to create a new route. /// Each implementation has bespoke docs that describe how the type is used, and what /// response is produced. pub enum Handler { diff --git a/src/lib.rs b/src/lib.rs index 1c8c7d5..caa0073 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -55,7 +55,7 @@ pub const GEMINI_PORT: u16 = 1965; use handling::Handler; #[derive(Clone)] -pub struct Server { +struct ServerInner { tls_acceptor: TlsAcceptor, routes: Arc>, timeout: Duration, @@ -66,11 +66,7 @@ pub struct Server { manager: UserManager, } -impl Server { - pub fn bind(addr: A) -> Builder { - Builder::bind(addr) - } - +impl ServerInner { async fn serve(self, listener: TcpListener) -> Result<()> { #[cfg(feature = "ratelimiting")] tokio::spawn(prune_ratelimit_log(self.rate_limits.clone())); @@ -239,7 +235,7 @@ impl Server { } } -pub struct Builder { +pub struct Server { addr: A, cert_path: PathBuf, key_path: PathBuf, @@ -254,8 +250,8 @@ pub struct Builder { certgen_mode: CertGenMode, } -impl Builder { - fn bind(addr: A) -> Self { +impl Server { + pub fn bind(addr: A) -> Self { Self { addr, timeout: Duration::from_secs(1), @@ -433,7 +429,7 @@ impl Builder { self.routes.shrink(); - let server = Server { + let server = ServerInner { tls_acceptor: TlsAcceptor::from(config), routes: Arc::new(self.routes), timeout: self.timeout, diff --git a/src/types/request.rs b/src/types/request.rs index 2c29f43..96363e1 100644 --- a/src/types/request.rs +++ b/src/types/request.rs @@ -75,7 +75,7 @@ impl Request { /// /// If the trailing segments have not been set, this method will panic, but this /// should only be possible if you are constructing the Request yourself. Requests - /// to handlers registered through [`add_route`](crate::Builder::add_route()) will + /// to handlers registered through [`add_route()`](crate::Server::add_route()) will /// always have trailing segments set. pub fn trailing_segments(&self) -> &Vec { self.trailing_segments.as_ref().unwrap()