diff options
| author | Mason Reed <mason@vector35.com> | 2026-03-13 12:20:27 -0700 |
|---|---|---|
| committer | Mason Reed <35282038+emesare@users.noreply.github.com> | 2026-03-24 18:46:48 -0700 |
| commit | c43ecea6535c12d8b04ca8cede1a35cb9fb66af9 (patch) | |
| tree | 5b3da92fcf2178b7a7ff8eecf3d3f933a5bf9bf8 /rust/src/lib.rs | |
| parent | a40a300cce8a798200562e9d4515116360dbd0b1 (diff) | |
[Rust] Move `ObjectDestructor` to own module and add some extra documentation
Diffstat (limited to 'rust/src/lib.rs')
| -rw-r--r-- | rust/src/lib.rs | 51 |
1 files changed, 1 insertions, 50 deletions
diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 254dd2f8..5f23a9f6 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -65,6 +65,7 @@ pub mod low_level_il; pub mod main_thread; pub mod medium_level_il; pub mod metadata; +pub mod object_destructor; pub mod platform; pub mod progress; pub mod project; @@ -90,8 +91,6 @@ pub mod websocket; pub mod worker_thread; pub mod workflow; -use crate::file_metadata::FileMetadata; -use crate::function::Function; use crate::progress::{NoProgressCallback, ProgressCallback}; use crate::string::raw_to_string; use binary_view::BinaryView; @@ -428,54 +427,6 @@ pub fn memory_info() -> HashMap<String, u64> { usage } -/// The trait required for receiving core object destruction callbacks. -pub trait ObjectDestructor: 'static + Sync + Sized { - fn destruct_view(&self, _view: &BinaryView) {} - fn destruct_file_metadata(&self, _metadata: &FileMetadata) {} - fn destruct_function(&self, _func: &Function) {} - - unsafe extern "C" fn cb_destruct_binary_view(ctxt: *mut c_void, view: *mut BNBinaryView) { - ffi_wrap!("ObjectDestructor::destruct_view", { - let view_type = &*(ctxt as *mut Self); - let view = BinaryView { handle: view }; - view_type.destruct_view(&view); - }) - } - - unsafe extern "C" fn cb_destruct_file_metadata(ctxt: *mut c_void, file: *mut BNFileMetadata) { - ffi_wrap!("ObjectDestructor::destruct_file_metadata", { - let view_type = &*(ctxt as *mut Self); - let file = FileMetadata::from_raw(file); - view_type.destruct_file_metadata(&file); - }) - } - - unsafe extern "C" fn cb_destruct_function(ctxt: *mut c_void, func: *mut BNFunction) { - ffi_wrap!("ObjectDestructor::destruct_function", { - let view_type = &*(ctxt as *mut Self); - let func = Function { handle: func }; - view_type.destruct_function(&func); - }) - } - - unsafe fn as_callbacks(&'static mut self) -> BNObjectDestructionCallbacks { - BNObjectDestructionCallbacks { - context: std::mem::transmute(&self), - destructBinaryView: Some(Self::cb_destruct_binary_view), - destructFileMetadata: Some(Self::cb_destruct_file_metadata), - destructFunction: Some(Self::cb_destruct_function), - } - } - - fn register(&'static mut self) { - unsafe { BNRegisterObjectDestructionCallbacks(&mut self.as_callbacks()) }; - } - - fn unregister(&'static mut self) { - unsafe { BNUnregisterObjectDestructionCallbacks(&mut self.as_callbacks()) }; - } -} - pub fn version() -> String { unsafe { BnString::into_string(BNGetVersionString()) } } |
