rustpython_vm/convert/
transmute_from.rs1use crate::{
2 object::{AsObject, PyObject, PyPayload, PyRef, PyResult},
3 vm::VirtualMachine,
4};
5
6pub unsafe trait TransmuteFromObject: Sized {
13 fn check(vm: &VirtualMachine, obj: &PyObject) -> PyResult<()>;
14}
15
16unsafe impl<T: PyPayload> TransmuteFromObject for PyRef<T> {
17 fn check(vm: &VirtualMachine, obj: &PyObject) -> PyResult<()> {
18 let class = T::class(&vm.ctx);
19 if obj.fast_isinstance(class) {
20 if obj.payload_is::<T>() {
21 Ok(())
22 } else {
23 Err(vm.new_downcast_runtime_error(class, obj))
24 }
25 } else {
26 Err(vm.new_downcast_type_error(class, obj))
27 }
28 }
29}