solomon_gremlin/structure/
property.rs1use std::collections::HashMap;
2
3use crate::conversion::{BorrowFromGValue, FromGValue};
4use crate::GValue;
5use crate::GremlinResult;
6
7pub type PropertyMap = HashMap<String, Property>;
8
9#[derive(Debug, PartialEq, Clone)]
10pub struct Property {
11 label: String,
12 value: Box<GValue>,
13}
14
15impl Property {
16 pub fn new<T, GT>(label: T, value: GT) -> Property
17 where
18 T: Into<String>,
19 GT: Into<GValue>,
20 {
21 Property {
22 label: label.into(),
23 value: Box::new(value.into()),
24 }
25 }
26
27 pub fn value(&self) -> &GValue {
28 &self.value
29 }
30
31 pub fn take<T>(self) -> GremlinResult<T>
32 where
33 T: FromGValue,
34 {
35 T::from_gvalue(*self.value)
36 }
37
38 pub fn get<T>(&self) -> GremlinResult<&T>
39 where
40 T: BorrowFromGValue,
41 {
42 T::from_gvalue(&self.value)
43 }
44
45 pub fn label(&self) -> &String {
46 &self.label
47 }
48}