Skip to main content

surrealdb_types/kind/
geometry.rs

1use std::fmt::Display;
2
3use serde::{Deserialize, Serialize};
4
5use crate::{SqlFormat, ToSql};
6
7/// Represents different types of geometric shapes in SurrealDB's type system
8///
9/// This enum defines the various geometry types that can be used in type definitions
10/// and schema validation.
11#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
12pub enum GeometryKind {
13	/// A single point in 2D space
14	Point,
15	/// A line consisting of multiple connected points
16	Line,
17	/// A polygon with an exterior boundary and optional interior holes
18	Polygon,
19	/// Multiple points
20	MultiPoint,
21	/// Multiple lines
22	MultiLine,
23	/// Multiple polygons
24	MultiPolygon,
25	/// A collection of different geometry types
26	Collection,
27}
28
29impl ToSql for GeometryKind {
30	fn fmt_sql(&self, f: &mut String, _fmt: SqlFormat) {
31		match self {
32			GeometryKind::Point => f.push_str("point"),
33			GeometryKind::Line => f.push_str("line"),
34			GeometryKind::Polygon => f.push_str("polygon"),
35			GeometryKind::MultiPoint => f.push_str("multipoint"),
36			GeometryKind::MultiLine => f.push_str("multiline"),
37			GeometryKind::MultiPolygon => f.push_str("multipolygon"),
38			GeometryKind::Collection => f.push_str("collection"),
39		}
40	}
41}
42
43impl Display for GeometryKind {
44	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
45		f.write_str(&self.to_sql())
46	}
47}