From 567bc397c003d6ee4283877ac93b6e4c592b9e33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pepe=20M=C3=A1rquez=20Romero?= Date: Sun, 13 Oct 2024 08:40:00 +0200 Subject: [PATCH] rework optional compilation --- fang/Cargo.toml | 8 ++++---- fang/src/asynk.rs | 20 +++++++++++++++----- fang/src/asynk/backend_sqlx.rs | 14 -------------- fang/src/lib.rs | 19 ++++++++++++++----- 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/fang/Cargo.toml b/fang/Cargo.toml index 5d8bc106..97be1657 100644 --- a/fang/Cargo.toml +++ b/fang/Cargo.toml @@ -26,10 +26,10 @@ blocking = ["dep:diesel", "dep:diesel-derive-enum", "dep:dotenvy", "diesel?/chro blocking-postgres = [ "blocking", "diesel?/postgres"] blocking-sqlite = ["blocking", "diesel?/sqlite" ] blocking-mysql = [ "blocking", "diesel?/mysql"] -migrations-postgres = ["migrations"] -migrations-sqlite = ["migrations"] -migrations-mysql = ["migrations"] -migrations = ["dep:diesel_migrations"] +migrations-postgres = ["migrations", "diesel?/postgres"] +migrations-sqlite = ["migrations", "diesel?/sqlite"] +migrations-mysql = ["migrations", "diesel?/mysql"] +migrations = ["dep:diesel_migrations", "dep:diesel"] [dev-dependencies] diff --git a/fang/src/asynk.rs b/fang/src/asynk.rs index 2a8ab87d..58d8fcf8 100644 --- a/fang/src/asynk.rs +++ b/fang/src/asynk.rs @@ -1,10 +1,20 @@ +// Here you should put all the backends based on sqlx library +#[cfg(any( + feature = "asynk-postgres", + feature = "asynk-mysql", + feature = "asynk-sqlite" +))] +pub mod backend_sqlx; + pub mod async_queue; pub mod async_runnable; pub mod async_worker; pub mod async_worker_pool; -pub mod backend_sqlx; -pub use async_queue::*; -pub use async_runnable::AsyncRunnable; -pub use async_worker::*; -pub use async_worker_pool::*; +// Here you should put all the backends. +#[cfg(any( + feature = "asynk-postgres", + feature = "asynk-mysql", + feature = "asynk-sqlite" +))] +pub use {async_queue::*, async_runnable::AsyncRunnable, async_worker::*, async_worker_pool::*}; diff --git a/fang/src/asynk/backend_sqlx.rs b/fang/src/asynk/backend_sqlx.rs index d0ed39c5..cfe57bb9 100644 --- a/fang/src/asynk/backend_sqlx.rs +++ b/fang/src/asynk/backend_sqlx.rs @@ -1,12 +1,6 @@ use chrono::{DateTime, Utc}; use sha2::Digest; use sha2::Sha256; - -#[cfg(all( - feature = "asynk-postgres", - feature = "asynk-sqlite", - feature = "asynk-mysql" -))] use { chrono::Duration, sqlx::any::AnyQueryResult, sqlx::database::HasArguments, sqlx::Database, sqlx::Encode, sqlx::Executor, sqlx::FromRow, sqlx::IntoArguments, sqlx::Pool, sqlx::Type, @@ -42,7 +36,6 @@ pub(crate) enum BackendSqlX { MySql, } -#[allow(dead_code)] #[derive(TypedBuilder, Clone)] pub(crate) struct QueryParams<'a> { #[builder(default, setter(strip_option))] @@ -65,7 +58,6 @@ pub(crate) struct QueryParams<'a> { task: Option<&'a Task>, } -#[allow(dead_code)] pub(crate) enum Res { Bigint(u64), Task(Task), @@ -145,7 +137,6 @@ use crate::FangTaskState; use crate::InternalPool; use crate::Task; -#[allow(dead_code)] pub(crate) fn calculate_hash(json: &str) -> String { let mut hasher = Sha256::new(); hasher.update(json.as_bytes()); @@ -153,11 +144,6 @@ pub(crate) fn calculate_hash(json: &str) -> String { hex::encode(result) } -#[cfg(all( - feature = "asynk-postgres", - feature = "asynk-sqlite", - feature = "asynk-mysql" -))] trait FangQueryable where DB: Database, diff --git a/fang/src/lib.rs b/fang/src/lib.rs index 79ceb2d5..f50abe7f 100644 --- a/fang/src/lib.rs +++ b/fang/src/lib.rs @@ -204,9 +204,18 @@ pub mod blocking; #[cfg(feature = "blocking")] pub use blocking::*; -#[cfg(feature = "asynk")] +#[cfg(any( + feature = "asynk-postgres", + feature = "asynk-mysql", + feature = "asynk-sqlite" +))] pub mod asynk; +#[cfg(any( + feature = "asynk-postgres", + feature = "asynk-mysql", + feature = "asynk-sqlite" +))] #[cfg(feature = "asynk")] pub use asynk::*; @@ -218,10 +227,10 @@ pub use async_trait::async_trait; pub use fang_derive_error::ToFangError; #[cfg(feature = "migrations")] -use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness}; - -#[cfg(feature = "migrations")] -use std::error::Error as SomeError; +use { + diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness}, + std::error::Error as SomeError, +}; #[cfg(feature = "migrations-postgres")] use diesel::pg::Pg;