From f0d1b789464e7d14b228a9bc19e17c7a64d2667d Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Sun, 21 Jul 2024 13:37:27 +0300
Subject: [PATCH] change: Add `serde` & `openapi` features to the core
Signed-off-by: Awiteb
---
Cargo.lock | 3 ---
crates/oxidetalis/Cargo.toml | 2 +-
crates/oxidetalis_config/Cargo.toml | 4 ++--
crates/oxidetalis_core/Cargo.toml | 11 ++++++-----
crates/oxidetalis_core/src/types/cipher.rs | 3 +++
crates/oxidetalis_core/src/types/mod.rs | 1 +
crates/oxidetalis_core/src/types/size.rs | 5 +++--
7 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 4b1fc6a..d443d58 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1951,11 +1951,8 @@ dependencies = [
"hex",
"hmac",
"k256",
- "log",
- "logcall",
"rand",
"salvo-oapi",
- "salvo_core",
"serde",
"sha2",
"thiserror",
diff --git a/crates/oxidetalis/Cargo.toml b/crates/oxidetalis/Cargo.toml
index f3a5764..64881f7 100644
--- a/crates/oxidetalis/Cargo.toml
+++ b/crates/oxidetalis/Cargo.toml
@@ -11,7 +11,7 @@ rust-version.workspace = true
[dependencies]
-oxidetalis_core = { workspace = true }
+oxidetalis_core = { workspace = true, features = ["openapi"]}
oxidetalis_config = { workspace = true }
oxidetalis_entities = { workspace = true }
oxidetalis_migrations = { workspace = true }
diff --git a/crates/oxidetalis_config/Cargo.toml b/crates/oxidetalis_config/Cargo.toml
index 3b6b05f..aa7aae1 100644
--- a/crates/oxidetalis_config/Cargo.toml
+++ b/crates/oxidetalis_config/Cargo.toml
@@ -11,14 +11,14 @@ rust-version.workspace = true
[dependencies]
-oxidetalis_core = { workspace = true }
+oxidetalis_core = { workspace = true, features = ["serde"]}
thiserror = { workspace = true }
serde = { workspace = true }
log = { workspace = true }
salvo_core = { workspace = true }
salvo-oapi = { workspace = true }
+base58 = { workspace = true }
clap = { version = "4.5.7", features = ["derive", "env"] }
-base58 = "0.2.0"
toml = "0.8.14"
derivative = "2.2.0"
diff --git a/crates/oxidetalis_core/Cargo.toml b/crates/oxidetalis_core/Cargo.toml
index 00c8746..36d24bb 100644
--- a/crates/oxidetalis_core/Cargo.toml
+++ b/crates/oxidetalis_core/Cargo.toml
@@ -13,11 +13,8 @@ rust-version.workspace = true
[dependencies]
base58 = { workspace = true }
thiserror = { workspace = true }
-salvo_core = { workspace = true }
-salvo-oapi = { workspace = true }
-serde = { workspace = true }
-log = { workspace = true }
-logcall = { workspace = true }
+salvo-oapi = { workspace = true, optional = true }
+serde = { workspace = true, optional = true }
cbc = { version = "0.1.2", features = ["alloc", "std"] }
k256 = { version = "0.13.3", default-features = false, features = ["ecdh"] }
rand = { version = "0.8.5", default-features = false, features = ["std_rng", "std"] }
@@ -26,6 +23,10 @@ hex = "0.4.3"
hmac = "0.12.1"
sha2 = "0.10.8"
+[features]
+openapi = ["dep:salvo-oapi"]
+serde = ["dep:serde"]
+
[lints.rust]
unsafe_code = "deny"
diff --git a/crates/oxidetalis_core/src/types/cipher.rs b/crates/oxidetalis_core/src/types/cipher.rs
index 7520c18..0c44a7e 100644
--- a/crates/oxidetalis_core/src/types/cipher.rs
+++ b/crates/oxidetalis_core/src/types/cipher.rs
@@ -22,6 +22,7 @@
use std::{fmt, str::FromStr};
use base58::{FromBase58, ToBase58};
+#[cfg(feature = "openapi")]
use salvo_oapi::{
schema::{
Schema as OapiSchema,
@@ -204,6 +205,7 @@ impl From<[u8; 56]> for Signature {
}
}
+#[cfg(feature = "openapi")]
impl ToSchema for PublicKey {
fn to_schema(_components: &mut salvo_oapi::Components) -> salvo_oapi::RefOr {
salvo_oapi::Object::new()
@@ -213,6 +215,7 @@ impl ToSchema for PublicKey {
}
}
+#[cfg(feature = "openapi")]
impl ToSchema for Signature {
fn to_schema(_components: &mut salvo_oapi::Components) -> salvo_oapi::RefOr {
salvo_oapi::Object::new()
diff --git a/crates/oxidetalis_core/src/types/mod.rs b/crates/oxidetalis_core/src/types/mod.rs
index 65bdeed..b6143aa 100644
--- a/crates/oxidetalis_core/src/types/mod.rs
+++ b/crates/oxidetalis_core/src/types/mod.rs
@@ -22,6 +22,7 @@
//! Oxidetalis server types
mod cipher;
+#[cfg(feature = "serde")]
mod impl_serde;
mod size;
diff --git a/crates/oxidetalis_core/src/types/size.rs b/crates/oxidetalis_core/src/types/size.rs
index ed7fe5d..21627b2 100644
--- a/crates/oxidetalis_core/src/types/size.rs
+++ b/crates/oxidetalis_core/src/types/size.rs
@@ -24,7 +24,7 @@
use std::{fmt, str::FromStr};
-use logcall::logcall;
+#[cfg(feature = "serde")]
use serde::{de::Error as DeError, Deserialize, Serialize};
/// Size type. Used to represent sizes in bytes, kilobytes, megabytes, and
@@ -79,7 +79,6 @@ impl fmt::Display for Size {
impl FromStr for Size {
type Err = String;
- #[logcall]
fn from_str(s: &str) -> Result {
let Some(first_alpha) = s.find(|c: char| c.is_alphabetic()) else {
return Err("Missing unit, e.g. `2MB`".to_owned());
@@ -103,6 +102,7 @@ impl FromStr for Size {
}
}
+#[cfg(feature = "serde")]
impl<'de> Deserialize<'de> for Size {
fn deserialize(deserializer: D) -> Result
where
@@ -115,6 +115,7 @@ impl<'de> Deserialize<'de> for Size {
}
}
+#[cfg(feature = "serde")]
impl Serialize for Size {
fn serialize(&self, serializer: S) -> Result
where