1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use std::convert::TryFrom;

use failure::Error;

use bolt_proto_derive::*;

use crate::bolt::Value;
use crate::error::ValueError;
use crate::native;

pub(crate) const SIGNATURE: u8 = 0x52;

#[derive(Debug, Clone, Hash, Eq, PartialEq, Signature, Marker, Serialize, Deserialize)]
pub struct Relationship {
    pub(crate) rel_identity: Box<Value>,
    pub(crate) start_node_identity: Box<Value>,
    pub(crate) end_node_identity: Box<Value>,
    pub(crate) rel_type: Box<Value>,
    pub(crate) properties: Box<Value>,
}

impl From<native::value::Relationship> for Relationship {
    fn from(native_rel: native::value::Relationship) -> Self {
        Self {
            rel_identity: Box::new(Value::from(native_rel.rel_identity)),
            start_node_identity: Box::new(Value::from(native_rel.start_node_identity)),
            end_node_identity: Box::new(Value::from(native_rel.end_node_identity)),
            rel_type: Box::new(Value::from(native_rel.rel_type)),
            properties: Box::new(Value::from(native_rel.properties)),
        }
    }
}

impl TryFrom<Value> for Relationship {
    type Error = Error;

    fn try_from(value: Value) -> Result<Self, Self::Error> {
        match value {
            Value::Relationship(rel) => Ok(rel),
            _ => Err(ValueError::InvalidConversion(value).into()),
        }
    }
}