(&self, f: F, vm: &VirtualMachine)
| 47 | } |
| 48 | |
| 49 | pub fn try_value_with<T, F, R>(&self, f: F, vm: &VirtualMachine) -> PyResult<R> |
| 50 | where |
| 51 | T: PyPayload, |
| 52 | F: Fn(&T) -> PyResult<R>, |
| 53 | { |
| 54 | let class = T::class(&vm.ctx); |
| 55 | let py_ref = if self.fast_isinstance(class) { |
| 56 | self.downcast_ref() |
| 57 | .ok_or_else(|| vm.new_downcast_runtime_error(class, self))? |
| 58 | } else { |
| 59 | return Err(vm.new_downcast_type_error(class, self)); |
| 60 | }; |
| 61 | f(py_ref) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | /// Lower-cost variation of `TryFromObject` |
no test coverage detected