Skip to content

Commit a1de5ca

Browse files
committed
Add AbstractType trait
1 parent 7146494 commit a1de5ca

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
@@ -691,6 +691,41 @@ impl Drop for TypeBuilder {
691691
//////////
692692
// Type
693693

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

0 commit comments

Comments
 (0)