@@ -350,13 +350,6 @@ To see how `CanWrapError` works in practice, we can redefine `LoadJsonConfig` to
350
350
# fn config_path (& self ) -> & PathBuf ;
351
351
# }
352
352
#
353
- # #[cgp_component {
354
- # provider: ErrorWrapper ,
355
- # }]
356
- # pub trait CanWrapError <Detail >: HasErrorType {
357
- # fn wrap_error (error : Self :: Error , detail : Detail ) -> Self :: Error ;
358
- # }
359
- #
360
353
pub struct LoadJsonConfig ;
361
354
362
355
impl <Context > ConfigLoader <Context > for LoadJsonConfig
@@ -430,13 +423,7 @@ So we can implement an error wrapper provider for `anyhow::Error` as follows:
430
423
# use core :: fmt :: Display ;
431
424
#
432
425
# use cgp :: prelude :: * ;
433
- #
434
- # #[cgp_component {
435
- # provider: ErrorWrapper ,
436
- # }]
437
- # pub trait CanWrapError <Detail >: HasErrorType {
438
- # fn wrap_error (error : Self :: Error , detail : Detail ) -> Self :: Error ;
439
- # }
426
+ # use cgp :: core :: error :: ErrorWrapper ;
440
427
#
441
428
pub struct WrapWithAnyhowContext ;
442
429
@@ -524,13 +511,6 @@ type as follows:
524
511
# fn config_path (& self ) -> & PathBuf ;
525
512
# }
526
513
#
527
- # #[cgp_component {
528
- # provider: ErrorWrapper ,
529
- # }]
530
- # pub trait CanWrapError <Detail >: HasErrorType {
531
- # fn wrap_error (error : Self :: Error , detail : Detail ) -> Self :: Error ;
532
- # }
533
- #
534
514
pub struct LoadJsonConfig ;
535
515
536
516
pub struct ErrLoadJsonConfig <'a , Context > {
@@ -627,13 +607,7 @@ as follows:
627
607
# use core :: fmt :: Debug ;
628
608
#
629
609
# use cgp :: prelude :: * ;
630
- #
631
- # #[cgp_component {
632
- # provider: ErrorWrapper ,
633
- # }]
634
- # pub trait CanWrapError <Detail >: HasErrorType {
635
- # fn wrap_error (error : Self :: Error , detail : Detail ) -> Self :: Error ;
636
- # }
610
+ # use cgp :: core :: error :: ErrorWrapper ;
637
611
#
638
612
pub struct WrapWithAnyhowDebug ;
639
613
@@ -691,21 +665,14 @@ pub mod traits {
691
665
pub trait HasConfigPath {
692
666
fn config_path (& self ) -> & PathBuf ;
693
667
}
694
-
695
- #[cgp_component {
696
- provider: ErrorWrapper ,
697
- }]
698
- pub trait CanWrapError <Detail >: HasErrorType {
699
- fn wrap_error (error : Self :: Error , detail : Detail ) -> Self :: Error ;
700
- }
701
668
}
702
669
703
670
pub mod impls {
704
671
use core :: fmt :: {Debug , Display };
705
672
use std :: path :: PathBuf ;
706
673
use std :: {fs, io};
707
674
708
- use cgp :: core :: error :: {ErrorRaiser , ProvideErrorType };
675
+ use cgp :: core :: error :: {ErrorRaiser , ErrorWrapper , ProvideErrorType };
709
676
use cgp :: prelude :: * ;
710
677
use serde :: Deserialize ;
711
678
@@ -819,7 +786,7 @@ pub mod contexts {
819
786
use std :: path :: PathBuf ;
820
787
821
788
use cgp :: core :: component :: UseDelegate ;
822
- use cgp :: core :: error :: {ErrorRaiserComponent , ErrorTypeComponent };
789
+ use cgp :: core :: error :: {ErrorRaiserComponent , ErrorWrapperComponent , ErrorTypeComponent };
823
790
use cgp :: prelude :: * ;
824
791
use serde :: Deserialize ;
825
792
@@ -888,15 +855,12 @@ we can also make use of the `UseDelegate` pattern to implement delegated error w
888
855
``` rust
889
856
# extern crate cgp;
890
857
#
858
+ # use core :: marker :: PhantomData ;
859
+ #
891
860
# use cgp :: prelude :: * ;
892
- # use cgp :: core :: component :: UseDelegate ;
861
+ # use cgp :: core :: error :: ErrorWrapper ;
893
862
#
894
- # #[cgp_component {
895
- # provider: ErrorWrapper ,
896
- # }]
897
- # pub trait CanWrapError <Detail >: HasErrorType {
898
- # fn wrap_error (error : Self :: Error , detail : Detail ) -> Self :: Error ;
899
- # }
863
+ # pub struct UseDelegate <Components >(pub PhantomData <Components >);
900
864
#
901
865
impl <Context , Detail , Components > ErrorWrapper <Context , Detail > for UseDelegate <Components >
902
866
where
@@ -925,6 +889,7 @@ to different error wrappers, similar to how we dispatch the error raisers based
925
889
# use std :: path :: PathBuf ;
926
890
#
927
891
# use cgp :: core :: component :: UseDelegate ;
892
+ # use cgp :: core :: error :: ErrorWrapper ;
928
893
# use cgp :: prelude :: * ;
929
894
#
930
895
# #[cgp_component {
@@ -948,32 +913,14 @@ to different error wrappers, similar to how we dispatch the error raisers based
948
913
# pub trait HasConfigPath {
949
914
# fn config_path (& self ) -> & PathBuf ;
950
915
# }
951
- #
952
- # #[cgp_component {
953
- # provider: ErrorWrapper ,
954
- # }]
955
- # pub trait CanWrapError <Detail >: HasErrorType {
956
- # fn wrap_error (error : Self :: Error , detail : Detail ) -> Self :: Error ;
957
- # }
958
- #
959
- # impl <Context , Detail , Components > ErrorWrapper <Context , Detail > for UseDelegate <Components >
960
- # where
961
- # Context : HasErrorType ,
962
- # Components : DelegateComponent <Detail >,
963
- # Components :: Delegate : ErrorWrapper <Context , Detail >,
964
- # {
965
- # fn wrap_error (error : Context :: Error , detail : Detail ) -> Context :: Error {
966
- # Components :: Delegate :: wrap_error (error , detail )
967
- # }
968
- # }
969
916
# }
970
917
#
971
918
# pub mod impls {
972
919
# use core :: fmt :: {Debug , Display };
973
920
# use std :: path :: PathBuf ;
974
921
# use std :: {fs, io};
975
922
#
976
- # use cgp :: core :: error :: {ErrorRaiser , ProvideErrorType };
923
+ # use cgp :: core :: error :: {ErrorRaiser , ErrorWrapper , ProvideErrorType };
977
924
# use cgp :: prelude :: * ;
978
925
# use serde :: Deserialize ;
979
926
#
@@ -1099,7 +1046,7 @@ to different error wrappers, similar to how we dispatch the error raisers based
1099
1046
# use std :: path :: PathBuf ;
1100
1047
#
1101
1048
# use cgp :: core :: component :: UseDelegate ;
1102
- # use cgp :: core :: error :: {ErrorRaiserComponent , ErrorTypeComponent };
1049
+ # use cgp :: core :: error :: {ErrorRaiserComponent , ErrorWrapperComponent , ErrorTypeComponent };
1103
1050
# use cgp :: prelude :: * ;
1104
1051
# use serde :: Deserialize ;
1105
1052
#
0 commit comments