From ca0e32efb1e5b9eba157e9fd2eef178d9367c578 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Thu, 11 Dec 2025 14:45:23 -0500 Subject: [Rust] Restructure type APIs into `types` module This helps with documentation, giving a single module for those working with types to find related APIs Also split out enumeration and structure APIs into their own file, since they have their own backing data separate from `Type`. --- rust/src/component.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'rust/src/component.rs') diff --git a/rust/src/component.rs b/rust/src/component.rs index 4c5d5992..f038d5c3 100644 --- a/rust/src/component.rs +++ b/rust/src/component.rs @@ -2,7 +2,7 @@ use crate::binary_view::{BinaryView, BinaryViewExt}; use crate::function::Function; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; use crate::string::{BnString, IntoCStr}; -use crate::types::ComponentReferencedType; +use crate::types::Type; use std::ffi::c_char; use std::fmt::Debug; use std::ptr::NonNull; @@ -304,3 +304,24 @@ unsafe impl CoreArrayProviderInner for Component { Guard::new(Self::from_raw(raw_ptr), context) } } + +// TODO: Remove this struct, or make it not a ZST with a terrible array provider. +/// ZST used only for `Array`. +pub struct ComponentReferencedType; + +impl CoreArrayProvider for ComponentReferencedType { + type Raw = *mut BNType; + type Context = (); + type Wrapped<'a> = &'a Type; +} + +unsafe impl CoreArrayProviderInner for ComponentReferencedType { + unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) { + BNComponentFreeReferencedTypes(raw, count) + } + + unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { + // SAFETY: &*mut BNType == &Type (*mut BNType == Type) + std::mem::transmute(raw) + } +} -- cgit v1.3.1