Skip to content

Commit 466fe3d

Browse files
committed
Add AbstractType trait
1 parent 7064468 commit 466fe3d

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

rust/src/types.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,41 @@ impl Drop for TypeBuilder {
695695
//////////
696696
// Type
697697

698+
pub trait AbstractType {
699+
fn resolve_type() -> Ref<Type>;
700+
}
701+
702+
macro_rules! abstract_type {
703+
($($t:ty => $e:expr),+) => {
704+
$(
705+
impl AbstractType for $t {
706+
fn resolve_type() -> Ref<Type> {
707+
$e
708+
}
709+
}
710+
)+
711+
}
712+
}
713+
714+
abstract_type! {
715+
u8 => Type::int(1, false),
716+
u16 => Type::int(2, false),
717+
u32 => Type::int(4, false),
718+
u64 => Type::int(8, false),
719+
i8 => Type::int(1, true),
720+
i16 => Type::int(2, true),
721+
i32 => Type::int(4, true),
722+
i64 => Type::int(8, true),
723+
f32 => Type::float(4),
724+
f64 => Type::float(8)
725+
}
726+
727+
impl<T: AbstractType, const N: usize> AbstractType for [T; N] {
728+
fn resolve_type() -> Ref<Type> {
729+
Type::array(&T::resolve_type(), N as u64)
730+
}
731+
}
732+
698733
#[repr(transparent)]
699734
pub struct Type {
700735
pub(crate) handle: *mut BNType,

0 commit comments

Comments
 (0)