Skip to main content

reifydb_core/interface/catalog/
property.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Copyright (c) 2025 ReifyDB
3
4use std::{
5	fmt,
6	fmt::{Display, Formatter},
7};
8
9use serde::{Deserialize, Serialize};
10
11use crate::interface::catalog::id::{ColumnId, ColumnPropertyId};
12
13#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14pub struct ColumnProperty {
15	pub id: ColumnPropertyId,
16	pub column: ColumnId,
17	pub property: ColumnPropertyKind,
18}
19
20#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
21pub enum ColumnPropertyKind {
22	Saturation(ColumnSaturationPolicy),
23}
24
25impl ColumnPropertyKind {
26	pub fn to_u8(&self) -> (u8, u8) {
27		match self {
28			ColumnPropertyKind::Saturation(policy) => match policy {
29				ColumnSaturationPolicy::Error => (0x01, 0x01),
30				ColumnSaturationPolicy::None => (0x01, 0x02),
31			},
32		}
33	}
34
35	pub fn from_u8(policy: u8, value: u8) -> ColumnPropertyKind {
36		match (policy, value) {
37			(0x01, 0x01) => ColumnPropertyKind::Saturation(ColumnSaturationPolicy::Error),
38			(0x01, 0x02) => ColumnPropertyKind::Saturation(ColumnSaturationPolicy::None),
39			_ => unimplemented!(),
40		}
41	}
42
43	pub fn default_saturation_policy() -> Self {
44		Self::Saturation(ColumnSaturationPolicy::default())
45	}
46}
47
48#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
49pub enum ColumnSaturationPolicy {
50	Error,
51	// Saturate,
52	// Wrap,
53	// Zero,
54	None,
55}
56
57impl Display for ColumnPropertyKind {
58	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
59		match self {
60			ColumnPropertyKind::Saturation(_) => f.write_str("saturation"),
61		}
62	}
63}
64
65pub const DEFAULT_COLUMN_SATURATION_POLICY: ColumnSaturationPolicy = ColumnSaturationPolicy::Error;
66
67impl Default for ColumnSaturationPolicy {
68	fn default() -> Self {
69		Self::Error
70	}
71}