You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
trezor-firmware/core/embed/rust/src/micropython/typ.rs

29 lines
699 B

use super::{
ffi,
obj::{Obj, ObjBase},
};
pub type Type = ffi::mp_obj_type_t;
impl Type {
pub fn is_type_of(&'static self, obj: Obj) -> bool {
if obj.is_ptr() {
// SAFETY: If `obj` is a pointer, it should always point to an object having
// `ObjBase` as the first field, making this cast safe.
unsafe {
let base = obj.as_ptr() as *const ObjBase;
(*base).type_ == self
}
} else {
false
}
}
pub const fn as_base(&'static self) -> ObjBase {
ObjBase { type_: self }
}
}
// SAFETY: We are in a single-threaded environment.
unsafe impl Sync for Type {}