grafbase_sdk/types/
directive_site.rs1use serde::Deserialize;
2
3use crate::{wit, SdkError};
4
5pub enum DirectiveSite<'a> {
7 Object(ObjectDirectiveSite<'a>),
9 FieldDefinition(FieldDefinitionDirectiveSite<'a>),
11 Interface(InterfaceDirectiveSite<'a>),
13 Union(UnionDirectiveSite<'a>),
15}
16
17impl<'a> From<&'a wit::DirectiveSite> for DirectiveSite<'a> {
18 fn from(value: &'a wit::DirectiveSite) -> Self {
19 match value {
20 wit::DirectiveSite::Object(site) => DirectiveSite::Object(site.into()),
21 wit::DirectiveSite::FieldDefinition(site) => DirectiveSite::FieldDefinition(site.into()),
22 wit::DirectiveSite::Interface(site) => DirectiveSite::Interface(site.into()),
23 wit::DirectiveSite::Union(site) => DirectiveSite::Union(site.into()),
24 }
25 }
26}
27
28impl<'a> DirectiveSite<'a> {
29 pub fn arguments<T>(&self) -> Result<T, SdkError>
32 where
33 T: Deserialize<'a>,
34 {
35 minicbor_serde::from_slice(match self {
36 DirectiveSite::Object(site) => &site.0.arguments,
37 DirectiveSite::FieldDefinition(site) => &site.0.arguments,
38 DirectiveSite::Interface(site) => &site.0.arguments,
39 DirectiveSite::Union(site) => &site.0.arguments,
40 })
41 .map_err(Into::into)
42 }
43}
44
45pub struct ObjectDirectiveSite<'a>(&'a wit::ObjectDirectiveSite);
47
48impl<'a> ObjectDirectiveSite<'a> {
49 #[inline]
51 pub fn object_name(&self) -> &str {
52 &self.0.object_name
53 }
54
55 pub fn arguments<T>(&self) -> Result<T, SdkError>
58 where
59 T: Deserialize<'a>,
60 {
61 minicbor_serde::from_slice(&self.0.arguments).map_err(Into::into)
62 }
63}
64
65impl<'a> From<&'a wit::ObjectDirectiveSite> for ObjectDirectiveSite<'a> {
66 fn from(value: &'a wit::ObjectDirectiveSite) -> Self {
67 Self(value)
68 }
69}
70
71pub struct FieldDefinitionDirectiveSite<'a>(&'a wit::FieldDefinitionDirectiveSite);
73
74impl<'a> FieldDefinitionDirectiveSite<'a> {
75 #[inline]
77 pub fn parent_type_name(&self) -> &str {
78 &self.0.parent_type_name
79 }
80
81 #[inline]
83 pub fn field_name(&self) -> &str {
84 &self.0.field_name
85 }
86
87 pub fn arguments<T>(&self) -> Result<T, SdkError>
90 where
91 T: Deserialize<'a>,
92 {
93 minicbor_serde::from_slice(&self.0.arguments).map_err(Into::into)
94 }
95}
96
97impl<'a> From<&'a wit::FieldDefinitionDirectiveSite> for FieldDefinitionDirectiveSite<'a> {
98 fn from(value: &'a wit::FieldDefinitionDirectiveSite) -> Self {
99 Self(value)
100 }
101}
102
103pub struct UnionDirectiveSite<'a>(&'a wit::UnionDirectiveSite);
105
106impl<'a> UnionDirectiveSite<'a> {
107 #[inline]
109 pub fn union_name(&self) -> &str {
110 &self.0.union_name
111 }
112
113 pub fn arguments<T>(&self) -> Result<T, SdkError>
116 where
117 T: Deserialize<'a>,
118 {
119 minicbor_serde::from_slice(&self.0.arguments).map_err(Into::into)
120 }
121}
122
123impl<'a> From<&'a wit::UnionDirectiveSite> for UnionDirectiveSite<'a> {
124 fn from(value: &'a wit::UnionDirectiveSite) -> Self {
125 Self(value)
126 }
127}
128
129pub struct InterfaceDirectiveSite<'a>(&'a wit::InterfaceDirectiveSite);
131
132impl<'a> InterfaceDirectiveSite<'a> {
133 #[inline]
135 pub fn interface_name(&self) -> &str {
136 &self.0.interface_name
137 }
138
139 pub fn arguments<T>(&self) -> Result<T, SdkError>
142 where
143 T: Deserialize<'a>,
144 {
145 minicbor_serde::from_slice(&self.0.arguments).map_err(Into::into)
146 }
147}
148
149impl<'a> From<&'a wit::InterfaceDirectiveSite> for InterfaceDirectiveSite<'a> {
150 fn from(value: &'a wit::InterfaceDirectiveSite) -> Self {
151 Self(value)
152 }
153}