cognite/dto/
items.rs

1use serde::{Deserialize, Serialize};
2use serde_with::skip_serializing_none;
3
4/// A generic structure for handling items in requests and responses.
5#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
6#[serde(rename_all = "camelCase")]
7pub struct Items<C, E = ()> {
8    /// The items of the request or response.
9    pub items: C,
10    /// Additional fields, delegated to the `E` type.
11    #[serde(flatten)]
12    pub extra_fields: E,
13}
14
15impl<C> Items<C> {
16    /// Create a new `Items` instance with the provided items and no extra fields.
17    pub fn new(items: C) -> Self {
18        Self {
19            items,
20            extra_fields: (),
21        }
22    }
23}
24
25impl<C, E> Items<C, E> {
26    /// Create a new `Items` instance with the provided items and extra fields.
27    pub fn new_with_extra_fields(items: C, extra_fields: E) -> Self {
28        Self {
29            items,
30            extra_fields,
31        }
32    }
33}
34
35impl<C, E: Default> From<C> for Items<C, E> {
36    fn from(items: C) -> Self {
37        Items {
38            items,
39            extra_fields: E::default(),
40        }
41    }
42}
43
44/// A convenience type for `Items` using a `Vec` to store items.
45pub type ItemsVec<T, E = ()> = Items<Vec<T>, E>;
46
47/// Extra fields for `Items` types with cursor data.
48#[derive(Clone, Debug, Default, Serialize, Deserialize)]
49#[serde(rename_all = "camelCase")]
50#[skip_serializing_none]
51pub struct Cursor {
52    /// The cursor for the next page of items.
53    pub next_cursor: Option<String>,
54}
55
56/// Extra fields for `Items` types with the `ignoreUnknownIds` field.
57#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
58#[serde(rename_all = "camelCase")]
59#[skip_serializing_none]
60pub struct IgnoreUnknownIds {
61    /// Whether to ignore unknown IDs in the request.
62    pub ignore_unknown_ids: bool,
63}