Skip to main content

modkit/api/
api_dto.rs

1/// Marker trait for API DTOs. This trait should only be implemented
2/// via the `#[modkit_macros::api_dto]` attribute macro.
3#[doc(hidden)]
4pub trait RequestApiDto {}
5
6/// Marker trait for API DTOs. This trait should only be implemented
7/// via the `#[modkit_macros::api_dto]` attribute macro.
8#[doc(hidden)]
9pub trait ResponseApiDto {}
10
11macro_rules! impl_api_dto_trait {
12    (generic: $($t:ty),+ $(,)?) => {
13        $(
14            impl<T: RequestApiDto> RequestApiDto for $t {}
15            impl<T: ResponseApiDto> ResponseApiDto for $t {}
16        )*
17    };
18    (concrete: $($t:ty),+ $(,)?) => {
19        $(
20            impl RequestApiDto for $t {}
21            impl ResponseApiDto for $t {}
22        )*
23    };
24}
25
26// The following traits are implemented on specific types that are known
27// to be serializable/deserializable. This list should not be modified by an LLM,
28// but only by a developer that has a reason not to implement the api_dto macro on the types specified here
29impl_api_dto_trait!(
30    generic:
31    Vec<T>,
32    Option<T>,
33    Box<T>,
34    modkit_odata::Page<T>,
35    Result<T, anyhow::Error>,
36    Result<T, modkit_errors::Problem>,
37);
38impl_api_dto_trait!(
39    concrete:
40    serde_json::Value,
41    modkit_errors::Problem,
42);