tarantool_rs/client/schema/
mod.rs1pub use self::{
4 index::{GenericIndex, Index, IndexMetadata, OwnedIndex},
5 space::{Space, SpaceMetadata},
6};
7
8use std::fmt;
9
10use rmpv::Value;
11use serde::{Deserialize, Serialize};
12
13mod index;
14mod space;
15
16pub const USER_SPACE_MIN_ID: u32 = 512;
20
21pub const PRIMARY_INDEX_ID: u32 = 0;
23
24#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)]
31#[repr(u32)]
32pub enum SystemSpacesId {
33 VSpace = 281,
34 VIndex = 289,
35}
36
37#[derive(Clone, Debug, PartialEq, Eq)]
39pub enum SchemaEntityKey {
40 Name(String),
42 Id(u32),
44}
45
46impl fmt::Display for SchemaEntityKey {
47 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48 match self {
49 SchemaEntityKey::Name(x) => write!(f, "name '{x}'"),
50 SchemaEntityKey::Id(x) => write!(f, "id '{x}'"),
51 }
52 }
53}
54
55impl From<&str> for SchemaEntityKey {
56 fn from(value: &str) -> Self {
57 Self::Name(value.to_owned())
58 }
59}
60
61impl From<u32> for SchemaEntityKey {
62 fn from(value: u32) -> Self {
63 Self::Id(value)
64 }
65}
66
67impl From<SchemaEntityKey> for Value {
68 fn from(val: SchemaEntityKey) -> Self {
69 match val {
70 SchemaEntityKey::Name(x) => x.into(),
71 SchemaEntityKey::Id(x) => x.into(),
72 }
73 }
74}
75
76impl SchemaEntityKey {
77 pub(crate) fn space_index_id(&self) -> u32 {
78 match self {
79 SchemaEntityKey::Name(_) => 2,
80 SchemaEntityKey::Id(_) => 0,
81 }
82 }
83
84 pub(crate) fn into_value(self) -> Value {
85 self.into()
86 }
87}