cynic_parser/schema_coordinates/
directive.rs1use core::fmt;
2
3use crate::Span;
4
5use super::Name;
6
7#[derive(Clone, Debug, Eq)]
8pub struct DirectiveCoordinate {
9 pub(super) name: Name,
10 pub(super) span: Span,
11}
12
13impl PartialEq for DirectiveCoordinate {
14 fn eq(&self, other: &Self) -> bool {
15 self.name == other.name
16 }
17}
18
19impl std::hash::Hash for DirectiveCoordinate {
20 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
21 self.name.hash(state);
22 }
23}
24
25impl PartialOrd for DirectiveCoordinate {
26 fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
27 Some(self.cmp(other))
28 }
29}
30
31impl Ord for DirectiveCoordinate {
32 fn cmp(&self, other: &Self) -> std::cmp::Ordering {
33 self.name.cmp(&other.name)
34 }
35}
36
37impl DirectiveCoordinate {
38 pub fn new(name: impl Into<String>) -> Self {
39 Self {
40 name: Name::new(name.into()),
41 span: Span::default(),
42 }
43 }
44
45 pub fn span(&self) -> Span {
46 self.span
47 }
48
49 pub fn name_span(&self) -> Span {
50 self.name.span
51 }
52
53 pub fn name(&self) -> &str {
54 &self.name.value
55 }
56}
57
58impl fmt::Display for DirectiveCoordinate {
59 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
60 write!(f, "@{}", self.name.value)
61 }
62}