Merge Builder
and Server
in the public API into one concept
This commit is contained in:
parent
0b0d925979
commit
1766ab4c9c
|
@ -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`]
|
/// The most useful part of the documentation for this is the implementations of [`From`]
|
||||||
/// on it, as this is what can be passed to
|
/// 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
|
/// Each implementation has bespoke docs that describe how the type is used, and what
|
||||||
/// response is produced.
|
/// response is produced.
|
||||||
pub enum Handler {
|
pub enum Handler {
|
||||||
|
|
16
src/lib.rs
16
src/lib.rs
|
@ -55,7 +55,7 @@ pub const GEMINI_PORT: u16 = 1965;
|
||||||
use handling::Handler;
|
use handling::Handler;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Server {
|
struct ServerInner {
|
||||||
tls_acceptor: TlsAcceptor,
|
tls_acceptor: TlsAcceptor,
|
||||||
routes: Arc<RoutingNode<Handler>>,
|
routes: Arc<RoutingNode<Handler>>,
|
||||||
timeout: Duration,
|
timeout: Duration,
|
||||||
|
@ -66,11 +66,7 @@ pub struct Server {
|
||||||
manager: UserManager,
|
manager: UserManager,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Server {
|
impl ServerInner {
|
||||||
pub fn bind<A: ToSocketAddrs>(addr: A) -> Builder<A> {
|
|
||||||
Builder::bind(addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn serve(self, listener: TcpListener) -> Result<()> {
|
async fn serve(self, listener: TcpListener) -> Result<()> {
|
||||||
#[cfg(feature = "ratelimiting")]
|
#[cfg(feature = "ratelimiting")]
|
||||||
tokio::spawn(prune_ratelimit_log(self.rate_limits.clone()));
|
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,
|
addr: A,
|
||||||
cert_path: PathBuf,
|
cert_path: PathBuf,
|
||||||
key_path: PathBuf,
|
key_path: PathBuf,
|
||||||
|
@ -254,8 +250,8 @@ pub struct Builder<A> {
|
||||||
certgen_mode: CertGenMode,
|
certgen_mode: CertGenMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: ToSocketAddrs> Builder<A> {
|
impl<A: ToSocketAddrs> Server<A> {
|
||||||
fn bind(addr: A) -> Self {
|
pub fn bind(addr: A) -> Self {
|
||||||
Self {
|
Self {
|
||||||
addr,
|
addr,
|
||||||
timeout: Duration::from_secs(1),
|
timeout: Duration::from_secs(1),
|
||||||
|
@ -433,7 +429,7 @@ impl<A: ToSocketAddrs> Builder<A> {
|
||||||
|
|
||||||
self.routes.shrink();
|
self.routes.shrink();
|
||||||
|
|
||||||
let server = Server {
|
let server = ServerInner {
|
||||||
tls_acceptor: TlsAcceptor::from(config),
|
tls_acceptor: TlsAcceptor::from(config),
|
||||||
routes: Arc::new(self.routes),
|
routes: Arc::new(self.routes),
|
||||||
timeout: self.timeout,
|
timeout: self.timeout,
|
||||||
|
|
|
@ -75,7 +75,7 @@ impl Request {
|
||||||
///
|
///
|
||||||
/// If the trailing segments have not been set, this method will panic, but this
|
/// 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
|
/// 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.
|
/// always have trailing segments set.
|
||||||
pub fn trailing_segments(&self) -> &Vec<String> {
|
pub fn trailing_segments(&self) -> &Vec<String> {
|
||||||
self.trailing_segments.as_ref().unwrap()
|
self.trailing_segments.as_ref().unwrap()
|
||||||
|
|
Loading…
Reference in a new issue