change: Add serde & openapi features to the core

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb 2024-07-21 13:37:27 +03:00
parent 23469f3f5e
commit f0d1b78946
Signed by: awiteb
GPG key ID: 3F6B55640AA6682F
7 changed files with 16 additions and 13 deletions

3
Cargo.lock generated
View file

@ -1951,11 +1951,8 @@ dependencies = [
"hex",
"hmac",
"k256",
"log",
"logcall",
"rand",
"salvo-oapi",
"salvo_core",
"serde",
"sha2",
"thiserror",

View file

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

View file

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

View file

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

View file

@ -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<OapiSchema> {
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<OapiSchema> {
salvo_oapi::Object::new()

View file

@ -22,6 +22,7 @@
//! Oxidetalis server types
mod cipher;
#[cfg(feature = "serde")]
mod impl_serde;
mod size;

View file

@ -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<Self, Self::Err> {
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<D>(deserializer: D) -> Result<Self, D::Error>
where
@ -115,6 +115,7 @@ impl<'de> Deserialize<'de> for Size {
}
}
#[cfg(feature = "serde")]
impl Serialize for Size {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where