@@ -13,12 +13,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313See the License for the specific language governing permissions and 
1414limitations under the License. 
1515*/ 
16- use  alloc:: boxed:: Box ; 
17- use  alloc:: format; 
18- use  alloc:: string:: ToString ; 
16+ use  anyhow:: { bail,  Result } ; 
1917use  alloc:: vec:: Vec ; 
2018use  core:: any:: type_name; 
21- use  core:: error:: Error ; 
2219use  core:: slice:: from_raw_parts_mut; 
2320
2421pub  struct  InputDataSection  { 
@@ -31,16 +28,14 @@ impl InputDataSection {
3128        InputDataSection  {  ptr,  len } 
3229    } 
3330
34-     pub  fn  try_pop_shared_input_data_into < T > ( & self )  -> Result < T ,   Box < dyn   Error > > 
31+     pub  fn  try_pop_shared_input_data_into < T > ( & self )  -> Result < T > 
3532    where 
3633        T :  for < ' a >  TryFrom < & ' a  [ u8 ] > , 
3734    { 
3835        let  input_data_buffer = unsafe  {  from_raw_parts_mut ( self . ptr ,  self . len )  } ; 
3936
4037        if  input_data_buffer. is_empty ( )  { 
41-             return  Err ( "Got a 0-size buffer in pop_shared_input_data_into" 
42-                 . to_string ( ) 
43-                 . into ( ) ) ; 
38+             bail ! ( "Got a 0-size buffer in pop_shared_input_data_into" ) ; 
4439        } 
4540
4641        // get relative offset to next free address 
@@ -51,11 +46,7 @@ impl InputDataSection {
5146        ) ; 
5247
5348        if  stack_ptr_rel > self . len  || stack_ptr_rel < 16  { 
54-             return  Err ( format ! ( 
55-                 "Invalid stack pointer: {} in pop_shared_input_data_into" , 
56-                 stack_ptr_rel
57-             ) 
58-             . into ( ) ) ; 
49+             bail ! ( "Invalid stack pointer: {} in pop_shared_input_data_into" ,  stack_ptr_rel) ; 
5950        } 
6051
6152        // go back 8 bytes and read. This is the offset to the element on top of stack 
@@ -71,7 +62,7 @@ impl InputDataSection {
7162        let  type_t = match  T :: try_from ( buffer)  { 
7263            Ok ( t)  => Ok ( t) , 
7364            Err ( _e)  => { 
74-                 return   Err ( format ! ( "Unable to convert buffer to {}" ,  type_name:: <T >( ) ) . into ( ) ) ; 
65+                 bail ! ( "Unable to convert buffer to {}" ,  type_name:: <T >( ) ) ; 
7566            } 
7667        } ; 
7768
@@ -95,13 +86,11 @@ impl OutputDataSection {
9586        OutputDataSection  {  ptr,  len } 
9687    } 
9788
98-     pub  fn  push_shared_output_data ( & self ,  data :  Vec < u8 > )  -> Result < ( ) ,   Box < dyn   Error > >  { 
89+     pub  fn  push_shared_output_data ( & self ,  data :  Vec < u8 > )  -> Result < ( ) >  { 
9990        let  output_data_buffer = unsafe  {  from_raw_parts_mut ( self . ptr ,  self . len )  } ; 
10091
10192        if  output_data_buffer. is_empty ( )  { 
102-             return  Err ( "Got a 0-size buffer in push_shared_output_data" 
103-                 . to_string ( ) 
104-                 . into ( ) ) ; 
93+             bail ! ( "Got a 0-size buffer in push_shared_output_data" ) ; 
10594        } 
10695
10796        // get offset to next free address on the stack 
@@ -119,22 +108,14 @@ impl OutputDataSection {
119108        // It can be equal to the size, but never greater 
120109        // It can never be less than 8. An empty buffer's stack pointer is 8 
121110        if  stack_ptr_rel > self . len  || stack_ptr_rel < 8  { 
122-             return  Err ( format ! ( 
123-                 "Invalid stack pointer: {} in push_shared_output_data" , 
124-                 stack_ptr_rel
125-             ) 
126-             . into ( ) ) ; 
111+             bail ! ( "Invalid stack pointer: {} in push_shared_output_data" ,  stack_ptr_rel) ; 
127112        } 
128113
129114        // check if there is enough space in the buffer 
130115        let  size_required = data. len ( )  + 8 ;  // the data plus the pointer pointing to the data 
131116        let  size_available = self . len  - stack_ptr_rel; 
132117        if  size_required > size_available { 
133-             return  Err ( format ! ( 
134-                 "Not enough space in shared output buffer. Required: {}, Available: {}" , 
135-                 size_required,  size_available
136-             ) 
137-             . into ( ) ) ; 
118+             bail ! ( "Not enough space in shared output buffer. Required: {}, Available: {}" ,  size_required,  size_available) ; 
138119        } 
139120
140121        // write the actual data 
0 commit comments