From f325aa7b6026a1daef84931baeb1f50d7da10c10 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Fri, 13 Mar 2026 12:22:27 -0700 Subject: [Rust] More appropriate impls for `PartialEq` and `Hash` for `FileMetadata` Utilize the unique `session_id` of the `FileMetadata` on comparisons and when hashing. --- rust/src/file_metadata.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'rust/src') diff --git a/rust/src/file_metadata.rs b/rust/src/file_metadata.rs index ce320dc5..b58daa55 100644 --- a/rust/src/file_metadata.rs +++ b/rust/src/file_metadata.rs @@ -22,6 +22,7 @@ use binaryninjacore_sys::*; use binaryninjacore_sys::{BNCreateDatabaseWithProgress, BNOpenExistingDatabaseWithProgress}; use std::ffi::c_void; use std::fmt::{Debug, Display, Formatter}; +use std::hash::{Hash, Hasher}; use std::path::{Path, PathBuf}; use crate::progress::{NoProgressCallback, ProgressCallback}; @@ -108,7 +109,6 @@ unsafe impl RefCountable for SaveSettings { /// **Important**: Because [`FileMetadata`] holds a strong reference to the [`BinaryView`]s and those /// views hold a strong reference to the file metadata, to end the cyclic reference a call to the /// [`FileMetadata::close`] is required. -#[derive(PartialEq, Eq, Hash)] pub struct FileMetadata { pub(crate) handle: *mut BNFileMetadata, } @@ -612,6 +612,20 @@ impl Display for FileMetadata { } } +impl PartialEq for FileMetadata { + fn eq(&self, other: &Self) -> bool { + self.session_id() == other.session_id() + } +} + +impl Eq for FileMetadata {} + +impl Hash for FileMetadata { + fn hash(&self, state: &mut H) { + self.session_id().hash(state); + } +} + unsafe impl Send for FileMetadata {} unsafe impl Sync for FileMetadata {} -- cgit v1.3.1