feat: Type-erase Database backend for simpler code
This commit is contained in:
parent
9933990fd3
commit
ccbd97b836
17 changed files with 108 additions and 117 deletions
|
|
@ -9,7 +9,7 @@ use static_serve::embed_assets;
|
|||
#[cfg(not(feature = "embed"))]
|
||||
use tower_http::services::ServeDir;
|
||||
|
||||
use crate::db::{Database, DatabaseInterface};
|
||||
use crate::db::Database;
|
||||
use crate::listener::{Listener, ListenerKind};
|
||||
use crate::stream::{AbstractSocketAddr, AbstractStreamKind};
|
||||
|
||||
|
|
@ -62,14 +62,14 @@ impl AxumListener for Listener {
|
|||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct HttpState<D: DatabaseInterface> {
|
||||
pub db: Database<D>,
|
||||
pub struct HttpState {
|
||||
pub db: Database,
|
||||
pub sessions: HttpSessionManager,
|
||||
pub templates: Environment<'static>,
|
||||
}
|
||||
|
||||
impl<D: DatabaseInterface> HttpState<D> {
|
||||
pub fn new(db: Database<D>) -> Self {
|
||||
impl HttpState {
|
||||
pub fn new(db: Database) -> Self {
|
||||
let mut templates = Environment::new();
|
||||
#[cfg(feature = "embed")]
|
||||
minijinja_embed::load_templates!(&mut templates);
|
||||
|
|
@ -83,7 +83,7 @@ impl<D: DatabaseInterface> HttpState<D> {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn http_listen<D: DatabaseInterface>(listener: Listener, db: Database<D>) {
|
||||
pub async fn http_listen(listener: Listener, db: Database) {
|
||||
#[cfg(all(feature = "embed", feature = "noembed"))]
|
||||
compile_error!("You cannot have `embed` and `noembed` features enabled at the same time.");
|
||||
#[cfg(not(any(feature = "embed", feature = "noembed")))]
|
||||
|
|
|
|||
Loading…
Reference in a new issue