@@ -54,7 +54,7 @@ pub trait ParseScalarValue<S = DefaultScalarValue> {
54
54
/// # use std::{any::Any, fmt};
55
55
/// #
56
56
/// # use compact_str::CompactString;
57
- /// use derive_more::{Display, From, TryInto};
57
+ /// use derive_more::with_trait:: {Display, From, TryInto};
58
58
/// use juniper::ScalarValue;
59
59
/// use serde::{de, Deserialize, Deserializer, Serialize};
60
60
///
@@ -84,7 +84,7 @@ pub trait ParseScalarValue<S = DefaultScalarValue> {
84
84
///
85
85
/// // Custom implementation of `ScalarValue::from_displayable()` method
86
86
/// // for efficient conversions from `CompactString` into `MyScalarValue`.
87
- /// fn from_compact_str<Str: fmt:: Display + Any + ?Sized>(s: &Str) -> MyScalarValue {
87
+ /// fn from_compact_str<Str: Display + Any + ?Sized>(s: &Str) -> MyScalarValue {
88
88
/// use juniper::AnyExt as _; // allows downcasting directly on types without `dyn`
89
89
///
90
90
/// if let Some(s) = s.downcast_ref::<CompactString>() {
@@ -180,7 +180,7 @@ pub trait ParseScalarValue<S = DefaultScalarValue> {
180
180
/// [`Serialize`]: trait@serde::Serialize
181
181
pub trait ScalarValue :
182
182
fmt:: Debug
183
- + fmt :: Display
183
+ + Display
184
184
+ PartialEq
185
185
+ Clone
186
186
+ DeserializeOwned
@@ -474,7 +474,7 @@ pub trait ScalarValue:
474
474
}
475
475
}
476
476
477
- /// Creates this [`ScalarValue`] from the provided [`fmt:: Display`] type.
477
+ /// Creates this [`ScalarValue`] from the provided [`Display`]able type.
478
478
///
479
479
/// This method should be implemented if [`ScalarValue`] implementation uses some custom string
480
480
/// type inside to enable efficient conversion from values of this type.
@@ -485,7 +485,7 @@ pub trait ScalarValue:
485
485
///
486
486
/// See the [example in trait documentation](ScalarValue#example) for how it can be used.
487
487
#[ must_use]
488
- fn from_displayable < Str : fmt :: Display + Any + ?Sized > ( s : & Str ) -> Self {
488
+ fn from_displayable < Str : Display + Any + ?Sized > ( s : & Str ) -> Self {
489
489
s. to_string ( ) . into ( )
490
490
}
491
491
}
@@ -549,13 +549,13 @@ impl<'s, S: ScalarValue> FromScalarValue<'s, S> for &'s Scalar<S> {
549
549
type Error = Infallible ;
550
550
551
551
fn from_scalar_value ( v : & ' s S ) -> Result < Self , Self :: Error > {
552
- Ok ( Scalar :: ref_cast ( v ) )
552
+ Ok ( v . into ( ) )
553
553
}
554
554
}
555
555
556
556
/// Error of a [`ScalarValue`] not matching the expected type.
557
557
#[ derive( Clone , Debug , Display , Error ) ]
558
- #[ display( "Expected `{type_name}`, found: {}" , ScalarValueFmt ( * input) ) ]
558
+ #[ display( "Expected `{type_name}`, found: {}" , < & Scalar <_>> :: from ( * input) ) ]
559
559
pub struct WrongInputScalarTypeError < ' a , S : ScalarValue > {
560
560
/// Type name of the expected GraphQL scalar.
561
561
pub type_name : ArcStr ,
@@ -570,10 +570,22 @@ impl<'a, S: ScalarValue> IntoFieldError<S> for WrongInputScalarTypeError<'a, S>
570
570
}
571
571
}
572
572
573
- /// [`Display`]-formatter for a [`ScalarValue`] to render as a [`Value`].
574
- pub ( crate ) struct ScalarValueFmt < ' a , S : ScalarValue > ( pub & ' a S ) ;
573
+ /// Transparent wrapper over a value, indicating it being a [`ScalarValue`].
574
+ ///
575
+ /// Used in [`GraphQLScalar`] definitions to distinguish a concrete type for a generic
576
+ /// [`ScalarValue`], since Rust type inference fail do so for a generic value directly in macro
577
+ /// expansions.
578
+ #[ derive( Debug , Deref , RefCast ) ]
579
+ #[ repr( transparent) ]
580
+ pub struct Scalar < T : ScalarValue > ( T ) ;
581
+
582
+ impl < ' a , T : ScalarValue > From < & ' a T > for & ' a Scalar < T > {
583
+ fn from ( value : & ' a T ) -> Self {
584
+ Scalar :: ref_cast ( value)
585
+ }
586
+ }
575
587
576
- impl < ' a , S : ScalarValue > Display for ScalarValueFmt < ' a , S > {
588
+ impl < S : ScalarValue > Display for Scalar < S > {
577
589
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
578
590
if let Some ( s) = self . 0 . try_as_str ( ) {
579
591
write ! ( f, "\" {s}\" " )
@@ -583,16 +595,6 @@ impl<'a, S: ScalarValue> Display for ScalarValueFmt<'a, S> {
583
595
}
584
596
}
585
597
586
- /// Transparent wrapper over a value, indicating it being a [`ScalarValue`].
587
- ///
588
- /// Used in [`GraphQLScalar`] definitions to distinguish a concrete type for a generic
589
- /// [`ScalarValue`], since Rust type inference fail do so for a generic value directly in macro
590
- /// expansions.
591
- #[ derive( Debug , Deref , Display , RefCast ) ]
592
- #[ display( "{}" , ScalarValueFmt ( _0) ) ]
593
- #[ repr( transparent) ]
594
- pub struct Scalar < T : ScalarValue > ( T ) ;
595
-
596
598
/// Extension of [`Any`] for using its methods directly on the value without `dyn`.
597
599
pub trait AnyExt : Any {
598
600
/// Returns `true` if the this type is the same as `T`.
0 commit comments