@@ -70,28 +70,47 @@ macro_rules! impl_supported_return_type {
7070}
7171
7272/// A trait to handle either a [`SupportedReturnType`] or a [`Result<impl SupportedReturnType>`]
73- pub trait ResultType < E > {
73+ pub trait ResultType < E : core :: fmt :: Debug > {
7474 /// The return type of the supported return value
7575 type ReturnType : SupportedReturnType ;
7676
7777 /// Convert the return type into a `Result<impl SupportedReturnType>`
7878 fn into_result ( self ) -> Result < Self :: ReturnType , E > ;
79+
80+ /// Convert a result into this type, panicking if needed
81+ fn from_result ( res : Result < Self :: ReturnType , E > ) -> Self ;
7982}
8083
81- impl < T : SupportedReturnType , E > ResultType < E > for T {
84+ impl < T , E > ResultType < E > for T
85+ where
86+ T : SupportedReturnType ,
87+ E : core:: fmt:: Debug ,
88+ {
8289 type ReturnType = T ;
8390
8491 fn into_result ( self ) -> Result < Self :: ReturnType , E > {
8592 Ok ( self )
8693 }
94+
95+ fn from_result ( res : Result < Self :: ReturnType , E > ) -> Self {
96+ res. unwrap ( )
97+ }
8798}
8899
89- impl < T : SupportedReturnType , E > ResultType < E > for Result < T , E > {
100+ impl < T , E > ResultType < E > for Result < T , E >
101+ where
102+ T : SupportedReturnType ,
103+ E : core:: fmt:: Debug ,
104+ {
90105 type ReturnType = T ;
91106
92107 fn into_result ( self ) -> Result < Self :: ReturnType , E > {
93108 self
94109 }
110+
111+ fn from_result ( res : Result < Self :: ReturnType , E > ) -> Self {
112+ res
113+ }
95114}
96115
97116for_each_return_type ! ( impl_supported_return_type) ;
0 commit comments