MCPcopy Index your code
hub / github.com/RustPython/RustPython / try_value_with

Method try_value_with

crates/vm/src/convert/try_from.rs:49–62  ·  view source on GitHub ↗
(&self, f: F, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

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`

Callers 3

Calls 7

fast_isinstanceMethod · 0.80
ok_or_elseMethod · 0.80
downcast_refMethod · 0.80
ErrClass · 0.50
fFunction · 0.50

Tested by

no test coverage detected