@@ -17,7 +17,7 @@ use crate::{
1717 subscriptions:: GraphQLSubscriptionValue ,
1818 } ,
1919 value:: {
20- FromScalarValue , ParseScalarResult , ScalarValue , TryToPrimitive , Value ,
20+ FromScalarValue , ParseScalarResult , ScalarValue , ToScalarValue , TryToPrimitive , Value ,
2121 WrongInputScalarTypeError ,
2222 } ,
2323} ;
@@ -76,6 +76,15 @@ mod impl_string_scalar {
7676 }
7777 }
7878
79+ impl < S > ToScalarValue < S > for String
80+ where
81+ Self : Into < S > ,
82+ {
83+ fn to_scalar_value ( & self ) -> S {
84+ self . clone ( ) . into ( )
85+ }
86+ }
87+
7988 pub ( super ) fn to_output < S : ScalarValue > ( v : & str ) -> Value < S > {
8089 Value :: scalar ( v. to_owned ( ) )
8190 }
@@ -291,15 +300,6 @@ where
291300 }
292301}
293302
294- impl < S > ToInputValue < S > for & str
295- where
296- S : ScalarValue ,
297- {
298- fn to_input_value ( & self ) -> InputValue < S > {
299- InputValue :: scalar ( String :: from ( * self ) )
300- }
301- }
302-
303303impl < ' s , S > FromScalarValue < ' s , S > for & ' s str
304304where
305305 S : TryToPrimitive < ' s , Self , Error : IntoFieldError < S > > + ' s ,
@@ -311,6 +311,21 @@ where
311311 }
312312}
313313
314+ impl < S : ScalarValue > ToScalarValue < S > for str {
315+ fn to_scalar_value ( & self ) -> S {
316+ S :: from_displayable ( self )
317+ }
318+ }
319+
320+ impl < S > ToInputValue < S > for & str
321+ where
322+ str : ToScalarValue < S > ,
323+ {
324+ fn to_input_value ( & self ) -> InputValue < S > {
325+ InputValue :: scalar :: < S > ( self . to_scalar_value ( ) )
326+ }
327+ }
328+
314329#[ graphql_scalar]
315330#[ graphql( with = impl_boolean_scalar, from_input_with = __builtin) ]
316331type Boolean = bool ;
@@ -329,6 +344,15 @@ mod impl_boolean_scalar {
329344 }
330345 }
331346
347+ impl < S > ToScalarValue < S > for Boolean
348+ where
349+ Self : Into < S > ,
350+ {
351+ fn to_scalar_value ( & self ) -> S {
352+ ( * self ) . into ( )
353+ }
354+ }
355+
332356 pub ( super ) fn to_output < S : ScalarValue > ( v : & Boolean ) -> Value < S > {
333357 Value :: scalar ( * v)
334358 }
@@ -357,6 +381,15 @@ mod impl_int_scalar {
357381 }
358382 }
359383
384+ impl < S > ToScalarValue < S > for Int
385+ where
386+ Self : Into < S > ,
387+ {
388+ fn to_scalar_value ( & self ) -> S {
389+ ( * self ) . into ( )
390+ }
391+ }
392+
360393 pub ( super ) fn to_output < S : ScalarValue > ( v : & Int ) -> Value < S > {
361394 Value :: scalar ( * v)
362395 }
@@ -390,6 +423,15 @@ mod impl_float_scalar {
390423 }
391424 }
392425
426+ impl < S > ToScalarValue < S > for Float
427+ where
428+ Self : Into < S > ,
429+ {
430+ fn to_scalar_value ( & self ) -> S {
431+ ( * self ) . into ( )
432+ }
433+ }
434+
393435 pub ( super ) fn to_output < S : ScalarValue > ( v : & Float ) -> Value < S > {
394436 Value :: scalar ( * v)
395437 }
0 commit comments