Merge Builder and Server in the public API into one concept

This commit is contained in:
Emii Tatsuo 2020-11-25 15:52:44 -05:00
parent 0b0d925979
commit 1766ab4c9c
Signed by: Emi
GPG key ID: 68FAB2E2E6DFC98B
3 changed files with 8 additions and 12 deletions

View file

@ -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 {

View file

@ -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<RoutingNode<Handler>>,
timeout: Duration,
@ -66,11 +66,7 @@ pub struct Server {
manager: UserManager,
}
impl Server {
pub fn bind<A: ToSocketAddrs>(addr: A) -> Builder<A> {
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<A> {
pub struct Server<A> {
addr: A,
cert_path: PathBuf,
key_path: PathBuf,
@ -254,8 +250,8 @@ pub struct Builder<A> {
certgen_mode: CertGenMode,
}
impl<A: ToSocketAddrs> Builder<A> {
fn bind(addr: A) -> Self {
impl<A: ToSocketAddrs> Server<A> {
pub fn bind(addr: A) -> Self {
Self {
addr,
timeout: Duration::from_secs(1),
@ -433,7 +429,7 @@ impl<A: ToSocketAddrs> Builder<A> {
self.routes.shrink();
let server = Server {
let server = ServerInner {
tls_acceptor: TlsAcceptor::from(config),
routes: Arc::new(self.routes),
timeout: self.timeout,

View file

@ -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<String> {
self.trailing_segments.as_ref().unwrap()