Added Wrapper types and DateTimeInterval
This commit is contained in:
parent
ae775f4e9e
commit
00e894140f
99
Cargo.lock
generated
99
Cargo.lock
generated
@ -26,6 +26,21 @@ dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "android-tzdata"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
|
||||
|
||||
[[package]]
|
||||
name = "android_system_properties"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.7.6"
|
||||
@ -180,6 +195,27 @@ version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401"
|
||||
dependencies = [
|
||||
"android-tzdata",
|
||||
"iana-time-zone",
|
||||
"js-sys",
|
||||
"num-traits",
|
||||
"serde",
|
||||
"wasm-bindgen",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation-sys"
|
||||
version = "0.8.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.2.13"
|
||||
@ -315,6 +351,26 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_more"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a9b99b9cbbe49445b21764dc0625032a89b145a2642e67603e1c936f5458d05"
|
||||
dependencies = [
|
||||
"derive_more-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_more-impl"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "diesel"
|
||||
version = "2.2.2"
|
||||
@ -647,6 +703,29 @@ dependencies = [
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.60"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141"
|
||||
dependencies = [
|
||||
"android_system_properties",
|
||||
"core-foundation-sys",
|
||||
"iana-time-zone-haiku",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"windows-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone-haiku"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ident_case"
|
||||
version = "1.0.1"
|
||||
@ -703,6 +782,8 @@ name = "lib"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"chrono",
|
||||
"derive_more",
|
||||
"diesel-crud-derive",
|
||||
"diesel-crud-trait",
|
||||
"into-response-derive",
|
||||
@ -832,6 +913,15 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.16.0"
|
||||
@ -1717,6 +1807,15 @@ version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.52.0"
|
||||
|
@ -42,6 +42,10 @@ into-response-derive = { path = "crates/into_response_derive", optional = true }
|
||||
read-files = { path = "crates/read_files", optional = true }
|
||||
# Serialization / Deserialization
|
||||
serde = { version = "1.0", optional = true, features = ["derive"] }
|
||||
# Time
|
||||
chrono = { version = "0.4", optional = true, features = ["serde"] }
|
||||
# Utils
|
||||
derive_more = { version = "1.0", features = ["from", "constructor"] }
|
||||
|
||||
[workspace.dependencies]
|
||||
syn = "2.0"
|
||||
@ -60,3 +64,4 @@ nom = ["dep:nom"]
|
||||
serde = ["dep:serde"]
|
||||
derive = ["dep:into-response-derive", "dep:diesel-crud-derive"]
|
||||
read-files = ["dep:read-files"]
|
||||
time = ["dep:chrono"]
|
||||
|
@ -3,6 +3,7 @@ use proc_macro::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::DeriveInput;
|
||||
|
||||
// TODO derive generic types
|
||||
pub fn into_response_derive_impl(input: DeriveInput) -> TokenStream {
|
||||
let name = &input.ident;
|
||||
|
||||
|
21
examples/multipart_file/Cargo.lock
generated
21
examples/multipart_file/Cargo.lock
generated
@ -123,6 +123,26 @@ version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "derive_more"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a9b99b9cbbe49445b21764dc0625032a89b145a2642e67603e1c936f5458d05"
|
||||
dependencies = [
|
||||
"derive_more-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_more-impl"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encoding_rs"
|
||||
version = "0.8.34"
|
||||
@ -289,6 +309,7 @@ name = "lib"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"derive_more",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tower 0.5.0",
|
||||
|
@ -4,3 +4,5 @@ pub mod load;
|
||||
#[cfg(feature = "serde")]
|
||||
pub mod response;
|
||||
pub mod router;
|
||||
#[cfg(feature = "serde")]
|
||||
pub mod wrappers;
|
||||
|
20
src/axum/wrappers.rs
Normal file
20
src/axum/wrappers.rs
Normal file
@ -0,0 +1,20 @@
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use derive_more::{Constructor, From};
|
||||
use into_response_derive::IntoResponse;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, From, Constructor)]
|
||||
pub struct Array<T: Serialize> {
|
||||
pub data: Vec<T>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, IntoResponse, From, Constructor)]
|
||||
pub struct Count {
|
||||
pub count: usize,
|
||||
}
|
||||
|
||||
impl<T: Serialize> IntoResponse for Array<T> {
|
||||
fn into_response(self) -> Response {
|
||||
crate::from!(self).into_response()
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
#![allow(dead_code)]
|
||||
extern crate self as lib;
|
||||
|
||||
#[cfg(all(feature = "derive", feature = "diesel"))]
|
||||
pub extern crate diesel_crud_derive;
|
||||
@ -17,6 +18,8 @@ pub mod io;
|
||||
pub mod nom;
|
||||
#[cfg(feature = "serde")]
|
||||
pub mod serde;
|
||||
#[cfg(feature = "time")]
|
||||
pub mod time;
|
||||
pub mod traits;
|
||||
#[cfg(feature = "iter")]
|
||||
pub mod vector;
|
||||
|
@ -19,7 +19,7 @@ impl<T: Serialize> BaseResponse<T> {
|
||||
#[macro_export]
|
||||
macro_rules! from {
|
||||
($body:expr) => {
|
||||
BaseResponse::new(env!("CARGO_PKG_VERSION"), $body)
|
||||
$crate::serde::response::BaseResponse::new(env!("CARGO_PKG_VERSION"), $body)
|
||||
};
|
||||
}
|
||||
|
||||
|
8
src/time/common.rs
Normal file
8
src/time/common.rs
Normal file
@ -0,0 +1,8 @@
|
||||
use chrono::NaiveDateTime;
|
||||
use derive_more::Constructor;
|
||||
|
||||
#[derive(Debug, Clone, Copy, Constructor)]
|
||||
pub struct DateTimeInterval {
|
||||
pub start: NaiveDateTime,
|
||||
pub end: NaiveDateTime,
|
||||
}
|
1
src/time/mod.rs
Normal file
1
src/time/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod common;
|
Loading…
x
Reference in New Issue
Block a user