Skip to content

Commit c953977

Browse files
committed
[Rust] Make ReportCollection::add_* optionally take a view
To allow for creating reports outside the context of a view
1 parent ecb8f07 commit c953977

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

rust/src/interaction/report.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,55 +77,67 @@ impl ReportCollection {
7777
}
7878
}
7979

80-
pub fn add_text(&self, view: &BinaryView, title: &str, contents: &str) {
80+
pub fn add_text(&self, view: Option<&BinaryView>, title: &str, contents: &str) {
8181
let title = title.to_cstr();
8282
let contents = contents.to_cstr();
8383
unsafe {
8484
BNAddPlainTextReportToCollection(
8585
self.handle.as_ptr(),
86-
view.handle,
86+
view.map(|v| v.handle).unwrap_or(std::ptr::null_mut()),
8787
title.as_ptr(),
8888
contents.as_ptr(),
8989
)
9090
}
9191
}
9292

93-
pub fn add_markdown(&self, view: &BinaryView, title: &str, contents: &str, plaintext: &str) {
93+
pub fn add_markdown(
94+
&self,
95+
view: Option<&BinaryView>,
96+
title: &str,
97+
contents: &str,
98+
plaintext: &str,
99+
) {
94100
let title = title.to_cstr();
95101
let contents = contents.to_cstr();
96102
let plaintext = plaintext.to_cstr();
97103
unsafe {
98104
BNAddMarkdownReportToCollection(
99105
self.handle.as_ptr(),
100-
view.handle,
106+
view.map(|v| v.handle).unwrap_or(std::ptr::null_mut()),
101107
title.as_ptr(),
102108
contents.as_ptr(),
103109
plaintext.as_ptr(),
104110
)
105111
}
106112
}
107113

108-
pub fn add_html(&self, view: &BinaryView, title: &str, contents: &str, plaintext: &str) {
114+
pub fn add_html(
115+
&self,
116+
view: Option<&BinaryView>,
117+
title: &str,
118+
contents: &str,
119+
plaintext: &str,
120+
) {
109121
let title = title.to_cstr();
110122
let contents = contents.to_cstr();
111123
let plaintext = plaintext.to_cstr();
112124
unsafe {
113125
BNAddHTMLReportToCollection(
114126
self.handle.as_ptr(),
115-
view.handle,
127+
view.map(|v| v.handle).unwrap_or(std::ptr::null_mut()),
116128
title.as_ptr(),
117129
contents.as_ptr(),
118130
plaintext.as_ptr(),
119131
)
120132
}
121133
}
122134

123-
pub fn add_graph(&self, view: &BinaryView, title: &str, graph: &FlowGraph) {
135+
pub fn add_graph(&self, view: Option<&BinaryView>, title: &str, graph: &FlowGraph) {
124136
let title = title.to_cstr();
125137
unsafe {
126138
BNAddGraphReportToCollection(
127139
self.handle.as_ptr(),
128-
view.handle,
140+
view.map(|v| v.handle).unwrap_or(std::ptr::null_mut()),
129141
title.as_ptr(),
130142
graph.handle,
131143
)

rust/tests/interaction.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,14 @@ fn test_show_report_collection() {
161161

162162
register_interaction_handler(MyInteractionHandler {});
163163
let collection = ReportCollection::new();
164-
collection.add_text(&view, "title_report_0", "contents");
165-
collection.add_markdown(&view, "title_report_1", "# contents", "markdown_plain_text");
164+
collection.add_text(Some(&view), "title_report_0", "contents");
165+
collection.add_markdown(None, "title_report_1", "# contents", "markdown_plain_text");
166166
collection.add_html(
167-
&view,
167+
None,
168168
"title_report_2",
169169
"<html>contents</html>",
170170
"html_plain_text",
171171
);
172-
collection.add_graph(&view, "title_report_3", &FlowGraph::new());
172+
collection.add_graph(None, "title_report_3", &FlowGraph::new());
173173
collection.show("show_report_collection_title");
174174
}

0 commit comments

Comments
 (0)