Skip to main content

typedb_driver/concept/
value.rs

1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20use chrono::NaiveDateTime;
21
22#[derive(Clone, Debug, PartialEq)]
23pub enum Value {
24    Boolean(bool),
25    Long(i64),
26    Double(f64),
27    String(String),
28    DateTime(NaiveDateTime),
29}
30
31impl Value {
32    /// Retrieves the `ValueType` of this value concept.
33    ///
34    /// # Examples
35    ///
36    /// ```rust
37    /// value.get_value_type();
38    /// ```
39    pub fn get_type(&self) -> ValueType {
40        match self {
41            Self::Boolean(_) => ValueType::Boolean,
42            Self::Long(_) => ValueType::Long,
43            Self::Double(_) => ValueType::Double,
44            Self::String(_) => ValueType::String,
45            Self::DateTime(_) => ValueType::DateTime,
46        }
47    }
48}
49
50/// Represents the type of primitive value is held by a Value or Attribute.
51#[repr(C)]
52#[derive(Clone, Copy, Debug, PartialEq, Eq)]
53pub enum ValueType {
54    Object,
55    Boolean,
56    Long,
57    Double,
58    String,
59    DateTime,
60}