1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-04 13:52:35 +00:00
trezor-firmware/core/embed/rust/src/micropython/typ.rs
2021-10-07 15:01:55 +02:00

29 lines
699 B
Rust

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 {}