Skip to content

Commit 6af5e64

Browse files
cgzonesetke
authored andcommitted
Store path in Binary as PathBuf
Retain the path property of the file member for future usage.
1 parent 0b67f37 commit 6af5e64

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/binary.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#[cfg(feature = "color")]
22
use colored::Colorize;
33
use serde::{Deserialize, Serialize};
4+
use std::path::PathBuf;
45
use std::{fmt, usize};
56

67
#[cfg(feature = "elf")]
@@ -89,7 +90,7 @@ impl fmt::Display for BinSpecificProperties {
8990
#[derive(Debug, Deserialize, Serialize)]
9091
pub struct Binary {
9192
pub binarytype: BinType,
92-
pub file: String,
93+
pub file: PathBuf,
9394
pub properties: BinSpecificProperties,
9495
}
9596
#[cfg(not(feature = "color"))]
@@ -98,7 +99,9 @@ impl fmt::Display for Binary {
9899
write!(
99100
f,
100101
"{}: | {} | File: {}",
101-
self.binarytype, self.properties, self.file
102+
self.binarytype,
103+
self.properties,
104+
self.file.display()
102105
)
103106
}
104107
}
@@ -111,14 +114,14 @@ impl fmt::Display for Binary {
111114
self.binarytype,
112115
self.properties,
113116
"File:".bold().underline(),
114-
self.file.bright_blue()
117+
self.file.display().to_string().bright_blue()
115118
)
116119
}
117120
}
118121
impl Binary {
119122
pub const fn new(
120123
binarytype: BinType,
121-
file: String,
124+
file: PathBuf,
122125
properties: BinSpecificProperties,
123126
) -> Self {
124127
Self { binarytype, file, properties }

src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ fn parse(file: &Path) -> Result<Vec<Binary>, ParseError> {
164164
if elf.is_64 { BinType::Elf64 } else { BinType::Elf32 };
165165
Ok(vec![Binary::new(
166166
bin_type,
167-
file.display().to_string(),
167+
file.to_path_buf(),
168168
BinSpecificProperties::Elf(results),
169169
)])
170170
}
@@ -175,7 +175,7 @@ fn parse(file: &Path) -> Result<Vec<Binary>, ParseError> {
175175
if pe.is_64 { BinType::PE64 } else { BinType::PE32 };
176176
Ok(vec![Binary::new(
177177
bin_type,
178-
file.display().to_string(),
178+
file.to_path_buf(),
179179
BinSpecificProperties::PE(results),
180180
)])
181181
}
@@ -190,7 +190,7 @@ fn parse(file: &Path) -> Result<Vec<Binary>, ParseError> {
190190
};
191191
Ok(vec![Binary::new(
192192
bin_type,
193-
file.display().to_string(),
193+
file.to_path_buf(),
194194
BinSpecificProperties::MachO(results),
195195
)])
196196
}
@@ -207,7 +207,7 @@ fn parse(file: &Path) -> Result<Vec<Binary>, ParseError> {
207207
};
208208
fat_bins.push(Binary::new(
209209
bin_type,
210-
file.display().to_string(),
210+
file.to_path_buf(),
211211
BinSpecificProperties::MachO(results),
212212
));
213213
}

0 commit comments

Comments
 (0)