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

Method downcast_exact

crates/vm/src/object/core.rs:1301–1313  ·  view source on GitHub ↗
(self, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

1299 /// another downcast can be attempted without unnecessary cloning.
1300 #[inline]
1301 pub fn downcast_exact<T: PyPayload>(self, vm: &VirtualMachine) -> Result<PyRefExact<T>, Self> {
1302 if self.class().is(T::class(&vm.ctx)) {
1303 // TODO: is this always true?
1304 assert!(
1305 self.downcastable::<T>(),
1306 "obj.__class__ is T::class() but payload is not T"
1307 );
1308 // SAFETY: just asserted that downcastable::<T>()
1309 Ok(unsafe { PyRefExact::new_unchecked(PyRef::from_obj_unchecked(self)) })
1310 } else {
1311 Err(self)
1312 }
1313 }
1314}
1315
1316impl PyObject {

Callers 5

get_int_fieldFunction · 0.80
get_opt_int_fieldFunction · 0.80
ast_from_objectMethod · 0.80
merge_objectMethod · 0.80
to_attributesMethod · 0.80

Calls 3

isMethod · 0.80
ErrClass · 0.50
classMethod · 0.45

Tested by

no test coverage detected