@@ -23,7 +23,7 @@ use std::fmt;
2323
2424use chrono:: { FixedOffset , TimeZone } ;
2525
26- use crate :: { ScalarValue , Value , graphql_scalar} ;
26+ use crate :: graphql_scalar;
2727
2828/// Date in the proleptic Gregorian calendar (without time zone).
2929///
@@ -36,26 +36,24 @@ use crate::{ScalarValue, Value, graphql_scalar};
3636///
3737/// [1]: https://graphql-scalars.dev/docs/scalars/local-date
3838/// [2]: https://docs.rs/chrono/latest/chrono/naive/struct.NaiveDate.html
39- #[ graphql_scalar(
39+ #[ graphql_scalar]
40+ #[ graphql(
4041 with = local_date,
4142 parse_token( String ) ,
4243 specified_by_url = "https://graphql-scalars.dev/docs/scalars/local-date" ,
4344) ]
4445pub type LocalDate = chrono:: NaiveDate ;
4546
4647mod local_date {
47- use super :: * ;
48+ use super :: LocalDate ;
4849
4950 /// Format of a [`LocalDate` scalar][1].
5051 ///
5152 /// [1]: https://graphql-scalars.dev/docs/scalars/local-date
5253 const FORMAT : & str = "%Y-%m-%d" ;
5354
54- pub ( super ) fn to_output < S > ( v : & LocalDate ) -> Value < S >
55- where
56- S : ScalarValue ,
57- {
58- Value :: scalar ( v. format ( FORMAT ) . to_string ( ) )
55+ pub ( super ) fn to_output ( v : & LocalDate ) -> String {
56+ v. format ( FORMAT ) . to_string ( ) // TODO: Optimize via `Display`?
5957 }
6058
6159 pub ( super ) fn from_input ( s : & str ) -> Result < LocalDate , Box < str > > {
@@ -75,7 +73,8 @@ mod local_date {
7573///
7674/// [1]: https://graphql-scalars.dev/docs/scalars/local-time
7775/// [2]: https://docs.rs/chrono/latest/chrono/naive/struct.NaiveTime.html
78- #[ graphql_scalar(
76+ #[ graphql_scalar]
77+ #[ graphql(
7978 with = local_time,
8079 parse_token( String ) ,
8180 specified_by_url = "https://graphql-scalars.dev/docs/scalars/local-time" ,
@@ -85,7 +84,7 @@ pub type LocalTime = chrono::NaiveTime;
8584mod local_time {
8685 use chrono:: Timelike as _;
8786
88- use super :: * ;
87+ use super :: LocalTime ;
8988
9089 /// Full format of a [`LocalTime` scalar][1].
9190 ///
@@ -102,18 +101,13 @@ mod local_time {
102101 /// [1]: https://graphql-scalars.dev/docs/scalars/local-time
103102 const FORMAT_NO_SECS : & str = "%H:%M" ;
104103
105- pub ( super ) fn to_output < S > ( v : & LocalTime ) -> Value < S >
106- where
107- S : ScalarValue ,
108- {
109- Value :: scalar (
110- if v. nanosecond ( ) == 0 {
111- v. format ( FORMAT_NO_MILLIS )
112- } else {
113- v. format ( FORMAT )
114- }
115- . to_string ( ) ,
116- )
104+ pub ( super ) fn to_output ( v : & LocalTime ) -> String {
105+ if v. nanosecond ( ) == 0 {
106+ v. format ( FORMAT_NO_MILLIS )
107+ } else {
108+ v. format ( FORMAT )
109+ }
110+ . to_string ( ) // TODO: Optimize via `Display`?
117111 }
118112
119113 pub ( super ) fn from_input ( s : & str ) -> Result < LocalTime , Box < str > > {
@@ -134,26 +128,24 @@ mod local_time {
134128///
135129/// [1]: https://graphql-scalars.dev/docs/scalars/local-date-time
136130/// [2]: https://docs.rs/chrono/latest/chrono/naive/struct.NaiveDateTime.html
137- #[ graphql_scalar(
131+ #[ graphql_scalar]
132+ #[ graphql(
138133 with = local_date_time,
139134 parse_token( String ) ,
140135 specified_by_url = "https://graphql-scalars.dev/docs/scalars/local-date-time" ,
141136) ]
142137pub type LocalDateTime = chrono:: NaiveDateTime ;
143138
144139mod local_date_time {
145- use super :: * ;
140+ use super :: LocalDateTime ;
146141
147142 /// Format of a [`LocalDateTime` scalar][1].
148143 ///
149144 /// [1]: https://graphql-scalars.dev/docs/scalars/local-date-time
150145 const FORMAT : & str = "%Y-%m-%dT%H:%M:%S" ;
151146
152- pub ( super ) fn to_output < S > ( v : & LocalDateTime ) -> Value < S >
153- where
154- S : ScalarValue ,
155- {
156- Value :: scalar ( v. format ( FORMAT ) . to_string ( ) )
147+ pub ( super ) fn to_output ( v : & LocalDateTime ) -> String {
148+ v. format ( FORMAT ) . to_string ( ) // TODO: Optimize via `Display`?
157149 }
158150
159151 pub ( super ) fn from_input ( s : & str ) -> Result < LocalDateTime , Box < str > > {
@@ -174,7 +166,8 @@ mod local_date_time {
174166/// [0]: https://datatracker.ietf.org/doc/html/rfc3339#section-5
175167/// [1]: https://graphql-scalars.dev/docs/scalars/date-time
176168/// [2]: https://docs.rs/chrono/latest/chrono/struct.DateTime.html
177- #[ graphql_scalar(
169+ #[ graphql_scalar]
170+ #[ graphql(
178171 with = date_time,
179172 parse_token( String ) ,
180173 specified_by_url = "https://graphql-scalars.dev/docs/scalars/date-time" ,
@@ -186,20 +179,19 @@ mod local_date_time {
186179pub type DateTime < Tz > = chrono:: DateTime < Tz > ;
187180
188181mod date_time {
189- use chrono:: { SecondsFormat , Utc } ;
182+ use std:: fmt;
183+
184+ use chrono:: { FixedOffset , SecondsFormat , TimeZone , Utc } ;
190185
191- use super :: * ;
186+ use super :: { DateTime , FromFixedOffset } ;
192187
193- pub ( super ) fn to_output < S , Tz > ( v : & DateTime < Tz > ) -> Value < S >
188+ pub ( super ) fn to_output < Tz > ( v : & DateTime < Tz > ) -> String
194189 where
195- S : ScalarValue ,
196- Tz : chrono:: TimeZone ,
190+ Tz : TimeZone ,
197191 Tz :: Offset : fmt:: Display ,
198192 {
199- Value :: scalar (
200- v. with_timezone ( & Utc )
201- . to_rfc3339_opts ( SecondsFormat :: AutoSi , true ) ,
202- )
193+ v. with_timezone ( & Utc )
194+ . to_rfc3339_opts ( SecondsFormat :: AutoSi , true ) // TODO: Optimize via `Display`?
203195 }
204196
205197 pub ( super ) fn from_input < Tz > ( s : & str ) -> Result < DateTime < Tz > , Box < str > >
0 commit comments