cassandra_cpp/cassandra/field.rs
1// use decimal::d128;
2
3use crate::cassandra::value::{Value, ValueType};
4
5use std::fmt;
6use std::fmt::Debug;
7use std::fmt::Display;
8use std::fmt::Formatter;
9
10// #[repr(C)]
11// #[derive(Copy,Debug,Clone)]
12// #[allow(missing_docs)]
13// pub enum FieldType {
14// PARTITION_KEY = 0,
15// CLUSTERING_KEY = 1,
16// REGULAR = 2,
17// COMPACT_VALUE = 3,
18// STATIC = 4,
19// UNKNOWN = 5,
20// }
21
22// impl FieldType {
23// // pub fn build(type_num: u32) -> Result<FieldType, u32> {
24// // match type_num {
25// // // 0 => Ok(PARTITION_KEY),
26// // // 1 => Ok(CLUSTERING_KEY),
27// // // 2 => Ok(REGULAR),
28// // // 3 => Ok(COMPACT_VALUE),
29// // // 4 => Ok(STATIC),
30// // // 5 => Ok(UNKNOWN),
31// // err => Err(err),
32// // }
33// // }
34// }
35
36/// A field's metadata
37//
38// Borrowed from wherever the value is borrowed from.
39pub struct Field<'a> {
40 /// The field's name
41 pub name: String,
42 /// The field's value
43 pub value: Value<'a>,
44}
45
46impl Debug for Field<'_> {
47 fn fmt(&self, f: &mut Formatter) -> fmt::Result {
48 write!(f, "{} Cassandra type", self.get_type())
49 }
50}
51
52impl Display for Field<'_> {
53 fn fmt(&self, f: &mut Formatter) -> fmt::Result {
54 write!(f, "{} Cassandra type", self.get_type())
55 }
56}
57
58impl<'a> Field<'a> {
59 /// Gets the name of this field
60 pub fn get_name(&self) -> String {
61 self.name.clone()
62 }
63
64 /// Gets the type of this field
65 pub fn get_type(&self) -> ValueType {
66 self.value.get_type()
67 }
68
69 /// Gets the value of this field
70 pub fn get_value(&self) -> &Value<'a> {
71 &self.value
72 }
73}