bluejay_visibility/
scalar_type_definition.rs1use crate::{Cache, Directives, Warden};
2use bluejay_core::definition::{self, HasDirectives, SchemaDefinition};
3
4pub struct ScalarTypeDefinition<'a, S: SchemaDefinition, W: Warden<SchemaDefinition = S>> {
5 inner: &'a S::CustomScalarTypeDefinition,
6 directives: Option<Directives<'a, S, W>>,
7 cache: &'a Cache<'a, S, W>,
8}
9
10impl<'a, S: SchemaDefinition, W: Warden<SchemaDefinition = S>> ScalarTypeDefinition<'a, S, W> {
11 pub(crate) fn new(
12 inner: &'a S::CustomScalarTypeDefinition,
13 cache: &'a Cache<'a, S, W>,
14 ) -> Self {
15 Self {
16 inner,
17 directives: inner.directives().map(|d| Directives::new(d, cache)),
18 cache,
19 }
20 }
21
22 pub fn inner(&self) -> &'a S::CustomScalarTypeDefinition {
23 self.inner
24 }
25}
26
27impl<S: SchemaDefinition, W: Warden<SchemaDefinition = S>> definition::ScalarTypeDefinition
28 for ScalarTypeDefinition<'_, S, W>
29{
30 fn description(&self) -> Option<&str> {
31 self.inner.description()
32 }
33
34 fn name(&self) -> &str {
35 self.inner.name()
36 }
37
38 fn coerce_input<const CONST: bool>(
39 &self,
40 value: &impl bluejay_core::Value<CONST>,
41 ) -> Result<(), std::borrow::Cow<'static, str>> {
42 self.cache
43 .warden()
44 .custom_scalar_definition_coerce_input(self.inner, value)
45 }
46}
47
48impl<'a, S: SchemaDefinition, W: Warden<SchemaDefinition = S>> HasDirectives
49 for ScalarTypeDefinition<'a, S, W>
50{
51 type Directives = Directives<'a, S, W>;
52
53 fn directives(&self) -> Option<&Self::Directives> {
54 self.directives.as_ref()
55 }
56}