@@ -54,7 +54,7 @@ pub trait ParseScalarValue<S = DefaultScalarValue> {
5454/// # use std::{any::Any, fmt};
5555/// #
5656/// # use compact_str::CompactString;
57- /// use derive_more::{Display, From, TryInto};
57+ /// use derive_more::with_trait:: {Display, From, TryInto};
5858/// use juniper::ScalarValue;
5959/// use serde::{de, Deserialize, Deserializer, Serialize};
6060///
@@ -84,7 +84,7 @@ pub trait ParseScalarValue<S = DefaultScalarValue> {
8484///
8585/// // Custom implementation of `ScalarValue::from_displayable()` method
8686/// // 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 {
8888/// use juniper::AnyExt as _; // allows downcasting directly on types without `dyn`
8989///
9090/// if let Some(s) = s.downcast_ref::<CompactString>() {
@@ -180,7 +180,7 @@ pub trait ParseScalarValue<S = DefaultScalarValue> {
180180/// [`Serialize`]: trait@serde::Serialize
181181pub trait ScalarValue :
182182 fmt:: Debug
183- + fmt :: Display
183+ + Display
184184 + PartialEq
185185 + Clone
186186 + DeserializeOwned
@@ -474,7 +474,7 @@ pub trait ScalarValue:
474474 }
475475 }
476476
477- /// Creates this [`ScalarValue`] from the provided [`fmt:: Display`] type.
477+ /// Creates this [`ScalarValue`] from the provided [`Display`]able type.
478478 ///
479479 /// This method should be implemented if [`ScalarValue`] implementation uses some custom string
480480 /// type inside to enable efficient conversion from values of this type.
@@ -485,7 +485,7 @@ pub trait ScalarValue:
485485 ///
486486 /// See the [example in trait documentation](ScalarValue#example) for how it can be used.
487487 #[ 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 {
489489 s. to_string ( ) . into ( )
490490 }
491491}
@@ -549,13 +549,13 @@ impl<'s, S: ScalarValue> FromScalarValue<'s, S> for &'s Scalar<S> {
549549 type Error = Infallible ;
550550
551551 fn from_scalar_value ( v : & ' s S ) -> Result < Self , Self :: Error > {
552- Ok ( Scalar :: ref_cast ( v ) )
552+ Ok ( v . into ( ) )
553553 }
554554}
555555
556556/// Error of a [`ScalarValue`] not matching the expected type.
557557#[ derive( Clone , Debug , Display , Error ) ]
558- #[ display( "Expected `{type_name}`, found: {}" , ScalarValueFmt ( * input) ) ]
558+ #[ display( "Expected `{type_name}`, found: {}" , < & Scalar <_>> :: from ( * input) ) ]
559559pub struct WrongInputScalarTypeError < ' a , S : ScalarValue > {
560560 /// Type name of the expected GraphQL scalar.
561561 pub type_name : ArcStr ,
@@ -570,10 +570,22 @@ impl<'a, S: ScalarValue> IntoFieldError<S> for WrongInputScalarTypeError<'a, S>
570570 }
571571}
572572
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+ }
575587
576- impl < ' a , S : ScalarValue > Display for ScalarValueFmt < ' a , S > {
588+ impl < S : ScalarValue > Display for Scalar < S > {
577589 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
578590 if let Some ( s) = self . 0 . try_as_str ( ) {
579591 write ! ( f, "\" {s}\" " )
@@ -583,16 +595,6 @@ impl<'a, S: ScalarValue> Display for ScalarValueFmt<'a, S> {
583595 }
584596}
585597
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-
596598/// Extension of [`Any`] for using its methods directly on the value without `dyn`.
597599pub trait AnyExt : Any {
598600 /// Returns `true` if the this type is the same as `T`.
0 commit comments