graphql_schema_diff/path/
display.rs1use super::*;
2
3impl fmt::Display for Path<'_> {
4 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5 match self {
6 Path::SchemaDefinition => f.write_str(":schema"),
7 Path::SchemaExtension(idx) => {
8 f.write_str(":schema")?;
9 write_index(idx, f)
10 }
11 Path::TypeDefinition(type_name, path_in_type) => {
12 f.write_str(type_name)?;
13
14 if let Some(path_in_type) = path_in_type {
15 f.write_str(".")?;
16 path_in_type.fmt(f)
17 } else {
18 Ok(())
19 }
20 }
21 Path::TypeExtension(type_name, extension_idx, path_in_type) => {
22 f.write_str(type_name)?;
23 write_index(extension_idx, f)?;
24
25 if let Some(path_in_type) = path_in_type {
26 f.write_str(".")?;
27 path_in_type.fmt(f)
28 } else {
29 Ok(())
30 }
31 }
32 Path::DirectiveDefinition(directive_name) => {
33 f.write_str("@")?;
34 f.write_str(directive_name)
35 }
36 }
37 }
38}
39
40impl fmt::Display for PathInType<'_> {
41 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42 match self {
43 PathInType::InField(field_name, path_in_field) => {
44 f.write_str(field_name)?;
45
46 if let Some(path_in_field) = path_in_field {
47 f.write_str(".")?;
48 path_in_field.fmt(f)
49 } else {
50 Ok(())
51 }
52 }
53 PathInType::InDirective(directive_name, directive_index) => {
54 f.write_str("@")?;
55 f.write_str(directive_name)?;
56 write_index(directive_index, f)
57 }
58 PathInType::InterfaceImplementation(interface_name) => {
59 f.write_str("&")?;
60 f.write_str(interface_name)
61 }
62 }
63 }
64}
65
66impl fmt::Display for PathInField<'_> {
67 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
68 match self {
69 PathInField::InArgument(name, path_in_arg) => {
70 f.write_str(name)?;
71 if let Some(path_in_arg) = path_in_arg {
72 f.write_str(".")?;
73 path_in_arg.fmt(f)
74 } else {
75 Ok(())
76 }
77 }
78 PathInField::InDirective(directive_name, directive_idx) => {
79 f.write_str("@")?;
80 f.write_str(directive_name)?;
81 write_index(directive_idx, f)
82 }
83 }
84 }
85}
86
87impl fmt::Display for PathInArgument<'_> {
88 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
89 match self {
90 PathInArgument::InDirective(name, idx) => {
91 f.write_str("@")?;
92 f.write_str(name)?;
93 write_index(idx, f)
94 }
95 }
96 }
97}
98
99fn write_index(idx: &usize, f: &mut fmt::Formatter<'_>) -> fmt::Result {
100 f.write_str("[")?;
101 fmt::Display::fmt(&idx, f)?;
102 f.write_str("]")
103}