From ae02e4cfe187752766a1137b2ce87a5642e89c44 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Tue, 9 Dec 2025 13:57:08 -0500 Subject: [Rust] Impl `Display` for `FileMetadata` --- rust/README.md | 2 +- rust/examples/simple.rs | 2 +- rust/src/file_metadata.rs | 10 ++++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) (limited to 'rust') diff --git a/rust/README.md b/rust/README.md index a18d46cd..60c4847c 100644 --- a/rust/README.md +++ b/rust/README.md @@ -29,7 +29,7 @@ fn main() { .load("/bin/cat") .expect("Couldn't open `/bin/cat`"); - println!("Filename: `{}`", bv.file().filename()); + println!("File: `{}`", bv.file()); println!("File size: `{:#x}`", bv.len()); println!("Function count: {}", bv.functions().len()); diff --git a/rust/examples/simple.rs b/rust/examples/simple.rs index f01d5267..66dbdfc0 100644 --- a/rust/examples/simple.rs +++ b/rust/examples/simple.rs @@ -12,7 +12,7 @@ fn main() { .load("/bin/cat") .expect("Couldn't open `/bin/cat`"); - println!("Filename: `{}`", bv.file().filename()); + println!("File: `{}`", bv.file()); println!("File size: `{:#x}`", bv.len()); println!("Function count: {}", bv.functions().len()); diff --git a/rust/src/file_metadata.rs b/rust/src/file_metadata.rs index 86e28a3e..dc9d36ff 100644 --- a/rust/src/file_metadata.rs +++ b/rust/src/file_metadata.rs @@ -27,7 +27,7 @@ use binaryninjacore_sys::{ }; use binaryninjacore_sys::{BNCreateDatabaseWithProgress, BNOpenExistingDatabaseWithProgress}; use std::ffi::c_void; -use std::fmt::Debug; +use std::fmt::{Debug, Display, Formatter}; use std::path::Path; use crate::progress::ProgressCallback; @@ -375,7 +375,7 @@ impl FileMetadata { } impl Debug for FileMetadata { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { f.debug_struct("FileMetadata") .field("filename", &self.filename()) .field("session_id", &self.session_id()) @@ -388,6 +388,12 @@ impl Debug for FileMetadata { } } +impl Display for FileMetadata { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.write_str(&self.filename()) + } +} + unsafe impl Send for FileMetadata {} unsafe impl Sync for FileMetadata {} -- cgit v1.3.1