bk_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)]
18pub enum ValueType {
19    Vector,
20    Scalar,
21    Matrix,
22    String,
23}
24
25impl Display for ValueType {
26    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
27        match *self {
28            ValueType::Scalar => write!(f, "scalar"),
29            ValueType::String => write!(f, "string"),
30            ValueType::Vector => write!(f, "vector"),
31            ValueType::Matrix => write!(f, "matrix"),
32        }
33    }
34}
35
36pub trait Value {
37    fn vtype(&self) -> ValueType;
38}
39
40#[cfg(test)]
41mod tests {
42    use super::*;
43
44    #[test]
45    fn test_value_type() {
46        assert_eq!(ValueType::Scalar.to_string(), "scalar");
47        assert_eq!(ValueType::String.to_string(), "string");
48        assert_eq!(ValueType::Vector.to_string(), "vector");
49        assert_eq!(ValueType::Matrix.to_string(), "matrix");
50    }
51}