surrealdb_core/sql/
edges.rs1use crate::sql::dir::Dir;
2use crate::sql::table::Tables;
3use crate::sql::thing::Thing;
4use revision::revisioned;
5use serde::{Deserialize, Serialize};
6use std::fmt;
7
8pub(crate) const TOKEN: &str = "$surrealdb::private::sql::Edges";
9
10#[revisioned(revision = 1)]
11#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
12#[serde(rename = "$surrealdb::private::sql::Edges")]
13#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
14#[non_exhaustive]
15pub struct Edges {
16 pub dir: Dir,
17 pub from: Thing,
18 pub what: Tables,
19}
20
21impl Edges {
22 #[doc(hidden)]
23 pub fn new(dir: Dir, from: Thing, what: Tables) -> Self {
24 Edges {
25 dir,
26 from,
27 what,
28 }
29 }
30}
31
32impl fmt::Display for Edges {
33 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
34 match self.what.len() {
35 0 => write!(f, "{}{}?", self.from, self.dir,),
36 1 => write!(f, "{}{}{}", self.from, self.dir, self.what),
37 _ => write!(f, "{}{}({})", self.from, self.dir, self.what),
38 }
39 }
40}