cognite/dto/core/
common.rs

1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5use serde_with::skip_serializing_none;
6
7#[derive(Serialize, Deserialize, Clone, Debug)]
8#[serde(rename_all = "camelCase")]
9/// Sort order for sorting core resources.
10pub enum CoreSortOrder {
11    /// Ascending
12    Asc,
13    /// Descending.
14    Desc,
15}
16
17#[derive(Serialize, Deserialize, Clone, Debug)]
18#[serde(rename_all = "camelCase")]
19/// Where to sort nulls.
20pub enum CoreSortNulls {
21    /// Nulls first,
22    First,
23    /// Nulls last
24    Last,
25    /// Translates to `First` for `Asc` and `Last` for `Desc`.
26    Auto,
27}
28
29#[skip_serializing_none]
30#[derive(Serialize, Deserialize, Debug, Default, Clone)]
31#[serde(rename_all = "camelCase")]
32/// Sort by a specific property
33pub struct CoreSortItem {
34    /// Property to sort by.
35    pub property: Vec<String>,
36    /// Sort order. Defaults to `Asc`.
37    pub order: Option<CoreSortOrder>,
38    /// Null behavior. Defaults to `Auto`.
39    pub nulls: Option<CoreSortNulls>,
40}
41
42#[derive(Serialize, Deserialize, Debug, Clone)]
43#[serde(tag = "type")]
44/// Geographic metadata.
45pub enum GeoLocation {
46    /// GeoJson Feature.
47    Feature(Feature),
48}
49
50#[skip_serializing_none]
51#[derive(Serialize, Deserialize, Debug, Clone)]
52#[serde(rename_all = "camelCase")]
53/// A geographical feature.
54pub struct Feature {
55    /// Represents the points, curves and surfaces in the coordinate space.
56    pub geometry: GeoLocationGeometry,
57    /// Additional properties in a String key -> Object value format.
58    pub properties: Option<HashMap<String, Value>>,
59}
60/// Coordinates of a point in 2D space, described as an array of 2 numbers.
61pub type Point = [f64; 2];
62/// Coordinates of a line described by a list of two or more points.
63/// Each point is defined as a pair of two numbers in an array,
64/// representing coordinates of a point in 2D space.
65pub type LineString = Vec<Point>;
66/// A linear ring is the boundary of a surface or the boundary of a hole in a surface.
67/// It is defined as a list consisting of 4 or more Points,
68/// where the first and last Point is equivalent.
69pub type LinearRing = Vec<Point>;
70/// List of one or more linear rings representing a shape.
71pub type Polygon = Vec<LinearRing>;
72#[derive(Serialize, Deserialize, Debug, Clone)]
73#[serde(tag = "type")]
74/// Geometry variants.
75pub enum GeoLocationGeometry {
76    /// Points in 2D space.
77    Point(GeometryItem<Point>),
78    /// A list of two or more points.
79    LineString(GeometryItem<LineString>),
80    /// A collection of linear rings that form a polygon.
81    Polygon(GeometryItem<Polygon>),
82    /// A set of multiple points.
83    MultiPoint(GeometryItem<Vec<Point>>),
84    /// A set of multiple lines.
85    MultiLineString(GeometryItem<Vec<LineString>>),
86    /// A set of multiple polygons.
87    MultiPolygon(GeometryItem<Vec<Polygon>>),
88}
89
90#[derive(Serialize, Deserialize, Debug, Clone)]
91#[serde(rename_all = "camelCase")]
92/// A geometry item.
93pub struct GeometryItem<T> {
94    /// Some form of coordinates.
95    pub coordinates: T,
96}