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(arg_name) => f.write_str(arg_name),
70 PathInField::InDirective(directive_name, directive_idx) => {
71 f.write_str("@")?;
72 f.write_str(directive_name)?;
73 write_index(directive_idx, f)
74 }
75 }
76 }
77}
78
79fn write_index(idx: &usize, f: &mut fmt::Formatter<'_>) -> fmt::Result {
80 f.write_str("[")?;
81 fmt::Display::fmt(&idx, f)?;
82 f.write_str("]")
83}