@@ -283,14 +283,33 @@ pub trait ScalarValue:
283283 ///
284284 /// Implementations should not implement this method, but rather implement the
285285 /// [`TryScalarValueTo<T>`] conversion directly.
286- fn try_to < ' a , T > ( & ' a self ) -> Result < T , <Self as TryScalarValueTo < ' a , T > >:: Error >
286+ fn try_to2 < ' a , T > ( & ' a self ) -> Result < T , <Self as TryScalarValueTo < ' a , T > >:: Error >
287287 where
288288 T : ' a ,
289289 Self : TryScalarValueTo < ' a , T , Error : IntoFieldError < Self > > ,
290290 {
291291 self . try_scalar_value_to ( )
292292 }
293293
294+ /// Tries to represent this [`ScalarValue`] as the specified type `T`.
295+ ///
296+ /// This method could be used instead of other helpers in case the [`TryScalarValueTo::Error`]
297+ /// is needed.
298+ ///
299+ /// # Implementation
300+ ///
301+ /// This method is an ergonomic alias for the [`TryScalarValueTo<T>`] conversion.
302+ ///
303+ /// Implementations should not implement this method, but rather implement the
304+ /// [`TryScalarValueTo<T>`] conversion directly.
305+ fn try_to < ' a , T > ( & ' a self ) -> Result < T , <Self as TryScalarValueTo < ' a , Scalar < T > > >:: Error >
306+ where
307+ T : ' a ,
308+ Self : TryScalarValueTo < ' a , Scalar < T > , Error : IntoFieldError < Self > > ,
309+ {
310+ self . try_scalar_value_to ( ) . map ( |s : Scalar < T > | s. 0 )
311+ }
312+
294313 /// Tries to represent this [`ScalarValue`] as a [`bool`] value.
295314 ///
296315 /// Use the [`ScalarValue::try_to::<bool>()`] method in case the [`TryScalarValueTo::Error`] is
@@ -477,6 +496,22 @@ impl<'me, S: ScalarValue> TryScalarValueTo<'me, &'me Scalar<S>> for S {
477496 }
478497}
479498
499+ impl < ' me , S : ScalarValue > TryScalarValueTo < ' me , Scalar < & ' me str > > for S {
500+ type Error = FieldError < Self > ;
501+
502+ fn try_scalar_value_to ( & ' me self ) -> FieldResult < Scalar < & ' me str > , Self > {
503+ self . try_scalar_value_to ( ) . map ( Scalar )
504+ }
505+ }
506+
507+ impl < ' me , T : FromScalarValue < S > + ' me , S : ScalarValue > TryScalarValueTo < ' me , Scalar < T > > for S {
508+ type Error = FieldError < Self > ;
509+
510+ fn try_scalar_value_to ( & ' me self ) -> FieldResult < Scalar < T > , Self > {
511+ T :: from_scalar_value ( self ) . map ( Scalar )
512+ }
513+ }
514+
480515pub trait FromScalarValue < S = DefaultScalarValue > : Sized {
481516 /// Performs the conversion.
482517 fn from_scalar_value ( v : & S ) -> FieldResult < Self , S > ;
@@ -519,8 +554,9 @@ impl<'a, S: ScalarValue> Display for ScalarValueFmt<'a, S> {
519554/// expansions.
520555#[ derive( Debug , Deref , Display , RefCast ) ]
521556#[ display( "{}" , ScalarValueFmt ( _0) ) ]
557+ #[ display( bound( T : ScalarValue ) ) ]
522558#[ repr( transparent) ]
523- pub struct Scalar < T : ScalarValue > ( T ) ;
559+ pub struct Scalar < T > ( T ) ;
524560
525561/// Extension of [`Any`] for using its methods directly on the value without `dyn`.
526562pub trait AnyExt : Any {
0 commit comments