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