@@ -194,7 +194,6 @@ pub trait ScalarValue:
194194 + for < ' a > TryScalarValueTo < ' a , f64 , Error : Display + IntoFieldError < Self > >
195195 + for < ' a > TryScalarValueTo < ' a , String , Error : Display + IntoFieldError < Self > >
196196 + for < ' a > TryScalarValueTo < ' a , & ' a str , Error : Display + IntoFieldError < Self > >
197- + for < ' a > TryScalarValueTo < ' a , & ' a Self , Error : Display + IntoFieldError < Self > >
198197 + TryInto < String >
199198 + ' static
200199{
@@ -248,14 +247,16 @@ pub trait ScalarValue:
248247 ///
249248 /// ```rust
250249 /// # use arcstr::ArcStr;
251- /// # use juniper::{FieldResult , GraphQLScalar, Scalar, ScalarValue, TryScalarValueTo, Value};
250+ /// # use juniper::{FromScalarValue , GraphQLScalar, Scalar, ScalarValue, TryScalarValueTo, Value};
252251 /// #
253252 /// #[derive(GraphQLScalar)]
254253 /// #[graphql(from_input_with = Self::from_input, transparent)]
255254 /// struct Name(ArcStr);
256255 ///
257256 /// impl Name {
258- /// fn from_input<S: ScalarValue>(v: &Scalar<S>) -> FieldResult<Self, S> {
257+ /// fn from_input<S: ScalarValue>(
258+ /// v: &Scalar<S>,
259+ /// ) -> Result<Self, <&str as FromScalarValue<S>>::Error> {
259260 /// // Check if our `ScalarValue` is represented by an `ArcStr` already, and if so,
260261 /// // do the cheap `Clone` instead of allocating a new `ArcStr` in its `From<&str>`
261262 /// // implementation.
@@ -282,7 +283,7 @@ pub trait ScalarValue:
282283 ///
283284 /// Implementations should not implement this method, but rather implement the
284285 /// [`TryScalarValueTo<T>`] conversion directly.
285- fn try_to < ' a , T > ( & ' a self ) -> FieldResult < T , Self >
286+ fn try_to < ' a , T > ( & ' a self ) -> Result < T , T :: Error >
286287 where
287288 T : FromScalarValue < ' a , Self > + ' a ,
288289 {
@@ -303,7 +304,7 @@ pub trait ScalarValue:
303304 /// [`TryScalarValueTo<bool>`] conversions for all the supported boolean types.
304305 #[ must_use]
305306 fn try_to_bool ( & self ) -> Option < bool > {
306- self . try_scalar_value_to ( ) . ok ( )
307+ self . try_to ( ) . ok ( )
307308 }
308309
309310 /// Tries to represent this [`ScalarValue`] as an [`i32`] value.
@@ -321,7 +322,7 @@ pub trait ScalarValue:
321322 /// less to an integer, if requested.
322323 #[ must_use]
323324 fn try_to_int ( & self ) -> Option < i32 > {
324- self . try_scalar_value_to ( ) . ok ( )
325+ self . try_to ( ) . ok ( )
325326 }
326327
327328 /// Tries to represent this [`ScalarValue`] as a [`f64`] value.
@@ -339,7 +340,7 @@ pub trait ScalarValue:
339340 /// all floating point values with 64 bit or less to a float, if requested.
340341 #[ must_use]
341342 fn try_to_float ( & self ) -> Option < f64 > {
342- self . try_scalar_value_to ( ) . ok ( )
343+ self . try_to ( ) . ok ( )
343344 }
344345
345346 /// Tries to represent this [`ScalarValue`] as a [`String`] value.
@@ -359,7 +360,7 @@ pub trait ScalarValue:
359360 /// [`TryScalarValueTo<String>`] conversions for all the supported string types, if requested.
360361 #[ must_use]
361362 fn try_to_string ( & self ) -> Option < String > {
362- self . try_scalar_value_to ( ) . ok ( )
363+ self . try_to ( ) . ok ( )
363364 }
364365
365366 /// Tries to convert this [`ScalarValue`] into a [`String`] value.
@@ -396,7 +397,7 @@ pub trait ScalarValue:
396397 /// requested.
397398 #[ must_use]
398399 fn try_as_str ( & self ) -> Option < & str > {
399- self . try_scalar_value_to ( ) . ok ( )
400+ self . try_to ( ) . ok ( )
400401 }
401402
402403 /// Converts this [`ScalarValue`] into another one via [`i32`], [`f64`], [`bool`] or [`String`]
@@ -449,7 +450,7 @@ pub trait ScalarValue:
449450/// all the required primitive types if `#[to_<type>]` and `#[as_<type>]` attributes are specified.
450451pub trait TryScalarValueTo < ' me , T : ' me > {
451452 /// Error if this [`ScalarValue`] doesn't represent the expected type.
452- type Error ;
453+ type Error : ' me ;
453454
454455 /// Tries to represent this [`ScalarValue`] as the expected type.
455456 ///
@@ -459,47 +460,25 @@ pub trait TryScalarValueTo<'me, T: 'me> {
459460 fn try_scalar_value_to ( & ' me self ) -> Result < T , Self :: Error > ;
460461}
461462
462- impl < ' me , S : ScalarValue > TryScalarValueTo < ' me , & ' me S > for S {
463- type Error = Infallible ;
464-
465- fn try_scalar_value_to ( & ' me self ) -> Result < & ' me S , Self :: Error > {
466- Ok ( self )
467- }
468- }
469-
470- impl < ' me , S : ScalarValue > TryScalarValueTo < ' me , & ' me Scalar < S > > for S {
471- type Error = Infallible ;
472-
473- fn try_scalar_value_to ( & ' me self ) -> Result < & ' me Scalar < S > , Self :: Error > {
474- Ok ( Scalar :: ref_cast ( self ) )
475- }
476- }
477-
478- impl < ' me , T , S > TryScalarValueTo < ' me , Scalar < T > > for S
479- where
480- T : FromScalarValue < ' me , S > + ' me ,
481- S : ScalarValue ,
482- {
483- type Error = FieldError < Self > ;
484-
485- fn try_scalar_value_to ( & ' me self ) -> FieldResult < Scalar < T > , Self > {
486- T :: from_scalar_value ( self ) . map ( Scalar )
487- }
488- }
489-
490463pub trait FromScalarValue < ' s , S : ' s = DefaultScalarValue > : Sized {
464+ type Error : IntoFieldError < S > + ' s ;
465+
491466 /// Performs the conversion.
492- fn from_scalar_value ( v : & ' s S ) -> FieldResult < Self , S > ;
467+ fn from_scalar_value ( v : & ' s S ) -> Result < Self , Self :: Error > ;
493468}
494469
495470impl < ' s , S > FromScalarValue < ' s , S > for & ' s S {
496- fn from_scalar_value ( v : & ' s S ) -> FieldResult < Self , S > {
471+ type Error = Infallible ;
472+
473+ fn from_scalar_value ( v : & ' s S ) -> Result < Self , Self :: Error > {
497474 Ok ( v)
498475 }
499476}
500477
501- impl < ' s , S > FromScalarValue < ' s , S > for & ' s Scalar < S > {
502- fn from_scalar_value ( v : & ' s S ) -> FieldResult < Self , S > {
478+ impl < ' s , S : ScalarValue > FromScalarValue < ' s , S > for & ' s Scalar < S > {
479+ type Error = Infallible ;
480+
481+ fn from_scalar_value ( v : & ' s S ) -> Result < Self , Self :: Error > {
503482 Ok ( Scalar :: ref_cast ( v) )
504483 }
505484}
@@ -541,9 +520,8 @@ impl<'a, S: ScalarValue> Display for ScalarValueFmt<'a, S> {
541520/// expansions.
542521#[ derive( Debug , Deref , Display , RefCast ) ]
543522#[ display( "{}" , ScalarValueFmt ( _0) ) ]
544- #[ display( bound( T : ScalarValue ) ) ]
545523#[ repr( transparent) ]
546- pub struct Scalar < T > ( T ) ;
524+ pub struct Scalar < T : ScalarValue > ( T ) ;
547525
548526/// Extension of [`Any`] for using its methods directly on the value without `dyn`.
549527pub trait AnyExt : Any {
0 commit comments