(&mut self, func: &Function, flags: FunctionFlags)
| 2942 | } |
| 2943 | |
| 2944 | fn generate_function_result(&mut self, func: &Function, flags: FunctionFlags) { |
| 2945 | if !flags.contains(FunctionFlags::TRAPPABLE) { |
| 2946 | self.print_result_ty(func.result, TypeMode::Owned); |
| 2947 | } else if let Some((r, _id, error_typename)) = self.special_case_trappable_error(func) { |
| 2948 | // Functions which have a single result `result<ok,err>` get special |
| 2949 | // cased to use the host_wasmtime_rust::Error<err>, making it possible |
| 2950 | // for them to trap or use `?` to propagate their errors |
| 2951 | self.push_str("Result<"); |
| 2952 | if let Some(ok) = r.ok { |
| 2953 | self.print_ty(&ok, TypeMode::Owned); |
| 2954 | } else { |
| 2955 | self.push_str("()"); |
| 2956 | } |
| 2957 | self.push_str(","); |
| 2958 | self.push_str(&error_typename); |
| 2959 | self.push_str(">"); |
| 2960 | } else { |
| 2961 | // All other functions get their return values wrapped in an wasmtime::Result. |
| 2962 | // Returning the anyhow::Error case can be used to trap. |
| 2963 | self.push_wasmtime_or_anyhow_result(); |
| 2964 | self.push_str("<"); |
| 2965 | self.print_result_ty(func.result, TypeMode::Owned); |
| 2966 | self.push_str(">"); |
| 2967 | } |
| 2968 | } |
| 2969 | |
| 2970 | fn extract_typed_function(&mut self, func: &Function) -> (String, String) { |
| 2971 | let snake = func_field_name(self.resolve, func); |
no test coverage detected