paperless_api/dto.rs
1//! DTO traits and helpers.
2
3use serde::Serialize;
4
5use crate::id::{ItemId, PaperlessId};
6
7/// Marker trait for DTOs used to create new items.
8pub trait CreateDto: Serialize {
9 /// The ID type for this item.
10 type Id: PaperlessId;
11
12 /// The base type for the DTO.
13 type BaseType: serde::de::DeserializeOwned;
14}
15
16/// Marker trait for DTOs used to update existing items.
17pub trait UpdateDto: Serialize {
18 /// The ID type for this item.
19 type Id: PaperlessId;
20
21 /// The base type for the DTO.
22 type BaseType: serde::de::DeserializeOwned;
23}
24
25/// Trait for items that can be managed via the Paperless API.
26pub trait Item: serde::de::DeserializeOwned {
27 /// The ID type for this item.
28 type Id: ItemId;
29
30 /// Returns the API endpoint for this item.
31 #[inline]
32 #[must_use]
33 fn endpoint() -> &'static str {
34 Self::Id::endpoint()
35 }
36
37 /// Returns the ID of this item.
38 #[must_use]
39 fn id(&self) -> Self::Id;
40}