Added Wrapper types and DateTimeInterval

This commit is contained in:
Martin Berg Alstad
2024-08-19 23:15:55 +02:00
parent ae775f4e9e
commit 00e894140f
10 changed files with 161 additions and 1 deletions

View File

@ -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
View 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()
}
}

View File

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

View File

@ -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
View 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
View File

@ -0,0 +1 @@
pub mod common;