promql_parser/parser/
value.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::fmt::{self, Display};
16
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18#[cfg_attr(feature = "ser", derive(serde::Serialize))]
19#[cfg_attr(feature = "ser", serde(rename_all = "camelCase"))]
20pub enum ValueType {
21    Vector,
22    Scalar,
23    Matrix,
24    String,
25}
26
27impl Display for ValueType {
28    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
29        match *self {
30            ValueType::Scalar => write!(f, "scalar"),
31            ValueType::String => write!(f, "string"),
32            ValueType::Vector => write!(f, "vector"),
33            ValueType::Matrix => write!(f, "matrix"),
34        }
35    }
36}
37
38pub trait Value {
39    fn vtype(&self) -> ValueType;
40}
41
42#[cfg(test)]
43mod tests {
44    use super::*;
45
46    #[test]
47    fn test_value_type() {
48        assert_eq!(ValueType::Scalar.to_string(), "scalar");
49        assert_eq!(ValueType::String.to_string(), "string");
50        assert_eq!(ValueType::Vector.to_string(), "vector");
51        assert_eq!(ValueType::Matrix.to_string(), "matrix");
52    }
53}