paperless-api 0.14.0

Async Paperless ngx API client
Documentation
//! DTO traits and helpers.

use serde::Serialize;

use crate::id::{ItemId, PaperlessId};

/// Marker trait for DTOs used to create new items.
pub trait CreateDto: Serialize {
    /// The ID type for this item.
    type Id: PaperlessId;

    /// The base type for the DTO.
    type BaseType: serde::de::DeserializeOwned;
}

/// Marker trait for DTOs used to update existing items.
pub trait UpdateDto: Serialize {
    /// The ID type for this item.
    type Id: PaperlessId;

    /// The base type for the DTO.
    type BaseType: serde::de::DeserializeOwned;
}

/// Trait for items that can be managed via the Paperless API.
pub trait Item: serde::de::DeserializeOwned {
    /// The ID type for this item.
    type Id: ItemId;

    /// Returns the API endpoint for this item.
    #[inline]
    #[must_use]
    fn endpoint() -> &'static str {
        Self::Id::endpoint()
    }

    /// Returns the ID of this item.
    #[must_use]
    fn id(&self) -> Self::Id;
}