Skip to content

Commit f325aa7

Browse files
committed
[Rust] More appropriate impls for PartialEq and Hash for FileMetadata
Utilize the unique `session_id` of the `FileMetadata` on comparisons and when hashing.
1 parent f9d2e6f commit f325aa7

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

rust/src/file_metadata.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use binaryninjacore_sys::*;
2222
use binaryninjacore_sys::{BNCreateDatabaseWithProgress, BNOpenExistingDatabaseWithProgress};
2323
use std::ffi::c_void;
2424
use std::fmt::{Debug, Display, Formatter};
25+
use std::hash::{Hash, Hasher};
2526
use std::path::{Path, PathBuf};
2627

2728
use crate::progress::{NoProgressCallback, ProgressCallback};
@@ -108,7 +109,6 @@ unsafe impl RefCountable for SaveSettings {
108109
/// **Important**: Because [`FileMetadata`] holds a strong reference to the [`BinaryView`]s and those
109110
/// views hold a strong reference to the file metadata, to end the cyclic reference a call to the
110111
/// [`FileMetadata::close`] is required.
111-
#[derive(PartialEq, Eq, Hash)]
112112
pub struct FileMetadata {
113113
pub(crate) handle: *mut BNFileMetadata,
114114
}
@@ -612,6 +612,20 @@ impl Display for FileMetadata {
612612
}
613613
}
614614

615+
impl PartialEq for FileMetadata {
616+
fn eq(&self, other: &Self) -> bool {
617+
self.session_id() == other.session_id()
618+
}
619+
}
620+
621+
impl Eq for FileMetadata {}
622+
623+
impl Hash for FileMetadata {
624+
fn hash<H: Hasher>(&self, state: &mut H) {
625+
self.session_id().hash(state);
626+
}
627+
}
628+
615629
unsafe impl Send for FileMetadata {}
616630
unsafe impl Sync for FileMetadata {}
617631

0 commit comments

Comments
 (0)