backhopper_xref_graph/
vertex.rs1use std::fmt;
13
14use backhopper_core::{ApplicationName, BehaviourName, Mfa, ModuleName};
15use serde::{Deserialize, Serialize};
16
17#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
18#[serde(tag = "kind", content = "value", rename_all = "snake_case")]
19pub enum Vertex {
20 Function(Mfa),
21 Module(ModuleName),
22 Application(ApplicationName),
23 Behaviour(BehaviourName),
24}
25
26impl Vertex {
27 pub fn as_module(&self) -> Option<&ModuleName> {
28 if let Vertex::Module(m) = self {
29 Some(m)
30 } else {
31 None
32 }
33 }
34
35 pub fn as_application(&self) -> Option<&ApplicationName> {
36 if let Vertex::Application(a) = self {
37 Some(a)
38 } else {
39 None
40 }
41 }
42
43 pub fn as_behaviour(&self) -> Option<&BehaviourName> {
44 if let Vertex::Behaviour(b) = self {
45 Some(b)
46 } else {
47 None
48 }
49 }
50}
51
52impl fmt::Display for Vertex {
53 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
54 match self {
55 Vertex::Function(mfa) => write!(f, "{mfa}"),
56 Vertex::Module(m) => write!(f, "{m}"),
57 Vertex::Application(a) => write!(f, "app:{a}"),
58 Vertex::Behaviour(b) => write!(f, "behaviour:{b}"),
59 }
60 }
61}