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", "hex",
"hmac", "hmac",
"k256", "k256",
"log",
"logcall",
"rand", "rand",
"salvo-oapi", "salvo-oapi",
"salvo_core",
"serde", "serde",
"sha2", "sha2",
"thiserror", "thiserror",

View file

@ -11,7 +11,7 @@ rust-version.workspace = true
[dependencies] [dependencies]
oxidetalis_core = { workspace = true } oxidetalis_core = { workspace = true, features = ["openapi"]}
oxidetalis_config = { workspace = true } oxidetalis_config = { workspace = true }
oxidetalis_entities = { workspace = true } oxidetalis_entities = { workspace = true }
oxidetalis_migrations = { workspace = true } oxidetalis_migrations = { workspace = true }

View file

@ -11,14 +11,14 @@ rust-version.workspace = true
[dependencies] [dependencies]
oxidetalis_core = { workspace = true } oxidetalis_core = { workspace = true, features = ["serde"]}
thiserror = { workspace = true } thiserror = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
log = { workspace = true } log = { workspace = true }
salvo_core = { workspace = true } salvo_core = { workspace = true }
salvo-oapi = { workspace = true } salvo-oapi = { workspace = true }
base58 = { workspace = true }
clap = { version = "4.5.7", features = ["derive", "env"] } clap = { version = "4.5.7", features = ["derive", "env"] }
base58 = "0.2.0"
toml = "0.8.14" toml = "0.8.14"
derivative = "2.2.0" derivative = "2.2.0"

View file

@ -13,11 +13,8 @@ rust-version.workspace = true
[dependencies] [dependencies]
base58 = { workspace = true } base58 = { workspace = true }
thiserror = { workspace = true } thiserror = { workspace = true }
salvo_core = { workspace = true } salvo-oapi = { workspace = true, optional = true }
salvo-oapi = { workspace = true } serde = { workspace = true, optional = true }
serde = { workspace = true }
log = { workspace = true }
logcall = { workspace = true }
cbc = { version = "0.1.2", features = ["alloc", "std"] } cbc = { version = "0.1.2", features = ["alloc", "std"] }
k256 = { version = "0.13.3", default-features = false, features = ["ecdh"] } k256 = { version = "0.13.3", default-features = false, features = ["ecdh"] }
rand = { version = "0.8.5", default-features = false, features = ["std_rng", "std"] } rand = { version = "0.8.5", default-features = false, features = ["std_rng", "std"] }
@ -26,6 +23,10 @@ hex = "0.4.3"
hmac = "0.12.1" hmac = "0.12.1"
sha2 = "0.10.8" sha2 = "0.10.8"
[features]
openapi = ["dep:salvo-oapi"]
serde = ["dep:serde"]
[lints.rust] [lints.rust]
unsafe_code = "deny" unsafe_code = "deny"

View file

@ -22,6 +22,7 @@
use std::{fmt, str::FromStr}; use std::{fmt, str::FromStr};
use base58::{FromBase58, ToBase58}; use base58::{FromBase58, ToBase58};
#[cfg(feature = "openapi")]
use salvo_oapi::{ use salvo_oapi::{
schema::{ schema::{
Schema as OapiSchema, Schema as OapiSchema,
@ -204,6 +205,7 @@ impl From<[u8; 56]> for Signature {
} }
} }
#[cfg(feature = "openapi")]
impl ToSchema for PublicKey { impl ToSchema for PublicKey {
fn to_schema(_components: &mut salvo_oapi::Components) -> salvo_oapi::RefOr<OapiSchema> { fn to_schema(_components: &mut salvo_oapi::Components) -> salvo_oapi::RefOr<OapiSchema> {
salvo_oapi::Object::new() salvo_oapi::Object::new()
@ -213,6 +215,7 @@ impl ToSchema for PublicKey {
} }
} }
#[cfg(feature = "openapi")]
impl ToSchema for Signature { impl ToSchema for Signature {
fn to_schema(_components: &mut salvo_oapi::Components) -> salvo_oapi::RefOr<OapiSchema> { fn to_schema(_components: &mut salvo_oapi::Components) -> salvo_oapi::RefOr<OapiSchema> {
salvo_oapi::Object::new() salvo_oapi::Object::new()

View file

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

View file

@ -24,7 +24,7 @@
use std::{fmt, str::FromStr}; use std::{fmt, str::FromStr};
use logcall::logcall; #[cfg(feature = "serde")]
use serde::{de::Error as DeError, Deserialize, Serialize}; use serde::{de::Error as DeError, Deserialize, Serialize};
/// Size type. Used to represent sizes in bytes, kilobytes, megabytes, and /// Size type. Used to represent sizes in bytes, kilobytes, megabytes, and
@ -79,7 +79,6 @@ impl fmt::Display for Size {
impl FromStr for Size { impl FromStr for Size {
type Err = String; type Err = String;
#[logcall]
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
let Some(first_alpha) = s.find(|c: char| c.is_alphabetic()) else { let Some(first_alpha) = s.find(|c: char| c.is_alphabetic()) else {
return Err("Missing unit, e.g. `2MB`".to_owned()); 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 { impl<'de> Deserialize<'de> for Size {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where where
@ -115,6 +115,7 @@ impl<'de> Deserialize<'de> for Size {
} }
} }
#[cfg(feature = "serde")]
impl Serialize for Size { impl Serialize for Size {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where where