graphrecords_query/index/
edge_endpoint.rs1use crate::{IndexDomain, QueryResult, index::GroupKey};
2use graphrecords_core::GraphRecord;
3use std::fmt::{self, Display, Formatter};
4
5#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
6pub enum EdgeEndpointRole {
7 Source,
8 Target,
9}
10
11impl Display for EdgeEndpointRole {
12 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
13 match self {
14 Self::Source => formatter.write_str("source"),
15 Self::Target => formatter.write_str("target"),
16 }
17 }
18}
19
20impl IndexDomain for EdgeEndpointRole {
21 type Index<'a> = Self;
22 type Owned = Self;
23
24 fn to_owned(index: &Self::Index<'_>) -> Self::Owned {
25 *index
26 }
27
28 fn from_owned(owned: &Self::Owned) -> Self::Index<'_> {
29 *owned
30 }
31}
32
33impl GroupKey for EdgeEndpointRole {
34 fn resolve_key<'a>(
35 _label: &'static str,
36 _graphrecord: &'a GraphRecord,
37 key: &Self::Owned,
38 ) -> QueryResult<Self::Index<'a>> {
39 Ok(*key)
40 }
41}