Skip to main content

paperless_api/
dto.rs

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