Skip to content

Commit c528f3a

Browse files
rbranElykDeer
authored andcommitted
fix rust doc code
1 parent 71a1c7e commit c528f3a

File tree

11 files changed

+111
-59
lines changed

11 files changed

+111
-59
lines changed

rust/src/architecture.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ pub trait FlagGroup: Sized + Clone + Copy {
296296
/// Types to represent the different comparisons, so for `cr1_lt` we
297297
/// would return a mapping along the lines of:
298298
///
299-
/// ```
299+
/// ```text
300300
/// cr1_signed -> LLFC_SLT,
301301
/// cr1_unsigned -> LLFC_ULT,
302302
/// ```

rust/src/binaryview.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,15 +1553,15 @@ pub type BinaryViewEventType = BNBinaryViewEventType;
15531553
///
15541554
/// # Example
15551555
///
1556-
/// ```rust
1556+
/// ```no_run
15571557
/// use binaryninja::binaryview::{BinaryView, BinaryViewEventHandler, BinaryViewEventType, register_binary_view_event};
15581558
///
15591559
/// struct EventHandlerContext {
15601560
/// // Context holding state available to event handler
15611561
/// }
15621562
///
15631563
/// impl BinaryViewEventHandler for EventHandlerContext {
1564-
/// fn on_event(&mut self, binary_view: &BinaryView) {
1564+
/// fn on_event(&self, binary_view: &BinaryView) {
15651565
/// // handle event
15661566
/// }
15671567
/// }

rust/src/command.rs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@
1616
//!
1717
//! All plugins need to provide one of the following functions for Binary Ninja to call:
1818
//!
19-
//! ```rust
20-
//! pub extern "C" fn CorePluginInit() -> bool {}
19+
//! ```no_run
20+
//! pub extern "C" fn CorePluginInit() -> bool {
21+
//! todo!();
22+
//! }
2123
//! ```
2224
//!
23-
//! ```rust
24-
//! pub extern "C" fn UIPluginInit() -> bool {}
25+
//! ```no_run
26+
//! pub extern "C" fn UIPluginInit() -> bool {
27+
//! todo!();
28+
//! }
2529
//! ```
2630
//!
2731
//! Both of these functions can call any of the following registration functions, though `CorePluginInit` is called during Binary Ninja core initialization, and `UIPluginInit` is called during Binary Ninja UI initialization.
@@ -62,7 +66,9 @@ where
6266
/// The function call required for generic commands; commands added in this way will be in the `Plugins` submenu of the menu bar.
6367
///
6468
/// # Example
65-
/// ```rust
69+
/// ```no_run
70+
/// # use binaryninja::command::Command;
71+
/// # use binaryninja::binaryview::BinaryView;
6672
/// struct MyCommand;
6773
///
6874
/// impl Command for MyCommand {
@@ -76,6 +82,7 @@ where
7682
/// }
7783
/// }
7884
///
85+
/// # use binaryninja::command::register;
7986
/// #[no_mangle]
8087
/// pub extern "C" fn CorePluginInit() -> bool {
8188
/// register(
@@ -160,7 +167,9 @@ where
160167
/// The function call required for generic commands; commands added in this way will be in the `Plugins` submenu of the menu bar.
161168
///
162169
/// # Example
163-
/// ```rust
170+
/// ```no_run
171+
/// # use binaryninja::command::AddressCommand;
172+
/// # use binaryninja::binaryview::BinaryView;
164173
/// struct MyCommand;
165174
///
166175
/// impl AddressCommand for MyCommand {
@@ -174,6 +183,7 @@ where
174183
/// }
175184
/// }
176185
///
186+
/// # use binaryninja::command::register_for_address;
177187
/// #[no_mangle]
178188
/// pub extern "C" fn CorePluginInit() -> bool {
179189
/// register_for_address(
@@ -258,10 +268,13 @@ where
258268
/// The function call required for generic commands; commands added in this way will be in the `Plugins` submenu of the menu bar.
259269
///
260270
/// # Example
261-
/// ```rust
271+
/// ```no_run
272+
/// # use std::ops::Range;
273+
/// # use binaryninja::command::RangeCommand;
274+
/// # use binaryninja::binaryview::BinaryView;
262275
/// struct MyCommand;
263276
///
264-
/// impl AddressCommand for MyCommand {
277+
/// impl RangeCommand for MyCommand {
265278
/// fn action(&self, view: &BinaryView, range: Range<u64>) {
266279
/// // Your code here
267280
/// }
@@ -272,6 +285,7 @@ where
272285
/// }
273286
/// }
274287
///
288+
/// # use binaryninja::command::register_for_range;
275289
/// #[no_mangle]
276290
/// pub extern "C" fn CorePluginInit() -> bool {
277291
/// register_for_range(
@@ -361,10 +375,14 @@ where
361375
/// The function call required for generic commands; commands added in this way will be in the `Plugins` submenu of the menu bar.
362376
///
363377
/// # Example
364-
/// ```rust
378+
/// ```no_run
379+
/// # use binaryninja::command::FunctionCommand;
380+
/// # use binaryninja::binaryview::BinaryView;
381+
/// # use binaryninja::function::Function;
382+
/// # use binaryninja::command::register_for_function;
365383
/// struct MyCommand;
366384
///
367-
/// impl AddressCommand for MyCommand {
385+
/// impl FunctionCommand for MyCommand {
368386
/// fn action(&self, view: &BinaryView, func: &Function) {
369387
/// // Your code here
370388
/// }

rust/src/debuginfo.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
//! And finally calling `binaryninja::debuginfo::DebugInfoParser::register` to register it with the core.
2828
//!
2929
//! Here's a minimal, complete example boilerplate-plugin:
30-
//! ```
30+
//! ```no_run
3131
//! use binaryninja::{
3232
//! binaryview::BinaryView,
3333
//! debuginfo::{CustomDebugInfoParser, DebugInfo, DebugInfoParser},
@@ -40,8 +40,9 @@
4040
//! true
4141
//! }
4242
//!
43-
//! fn parse_info(&self, _debug_info: &mut DebugInfo, _view: &BinaryView, _debug_file: &BinaryView, _progress: Box<dyn Fn(usize, usize) -> bool>) {
43+
//! fn parse_info(&self, _debug_info: &mut DebugInfo, _view: &BinaryView, _debug_file: &BinaryView, _progress: Box<dyn Fn(usize, usize) -> Result<(), ()>>) -> bool {
4444
//! println!("Parsing info");
45+
//! true
4546
//! }
4647
//! }
4748
//!
@@ -53,11 +54,14 @@
5354
//! ```
5455
//!
5556
//! `DebugInfo` will then be automatically applied to binary views that contain debug information (via the setting `analysis.debugInfo.internal`), binary views that provide valid external debug info files (`analysis.debugInfo.external`), or manually fetched/applied as below:
56-
//! ```
57-
//! let valid_parsers = DebugInfoParser::parsers_for_view(bv);
58-
//! let parser = valid_parsers[0];
59-
//! let debug_info = parser.parse_debug_info(bv);
60-
//! bv.apply_debug_info(debug_info);
57+
//! ```no_run
58+
//! # use binaryninja::debuginfo::DebugInfoParser;
59+
//! # use binaryninja::binaryview::BinaryViewExt;
60+
//! let bv = binaryninja::load("example").unwrap();
61+
//! let valid_parsers = DebugInfoParser::parsers_for_view(&bv);
62+
//! let parser = valid_parsers.get(0);
63+
//! let debug_info = parser.parse_debug_info(&bv, &bv, None, None).unwrap();
64+
//! bv.apply_debug_info(&debug_info);
6165
//! ```
6266
//!
6367
//! Multiple debug-info parsers can manually contribute debug info for a binary view by simply calling `parse_debug_info` with the
@@ -277,6 +281,14 @@ unsafe impl CoreOwnedArrayProvider for DebugInfoParser {
277281
}
278282
}
279283

284+
unsafe impl<'a> CoreArrayWrapper<'a> for DebugInfoParser {
285+
type Wrapped = Guard<'a, DebugInfoParser>;
286+
287+
unsafe fn wrap_raw(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped {
288+
Guard::new(DebugInfoParser { handle: *raw }, &())
289+
}
290+
}
291+
280292
///////////////////////
281293
// DebugFunctionInfo
282294

@@ -414,7 +426,10 @@ impl DebugInfo {
414426
}
415427

416428
/// Returns a generator of all functions provided by a named DebugInfoParser
417-
pub fn functions_by_name<S: BnStrCompatible>(&self, parser_name: S) -> Vec<DebugFunctionInfo> {
429+
pub fn functions_by_name<S: BnStrCompatible>(
430+
&self,
431+
parser_name: S
432+
) -> Vec<DebugFunctionInfo> {
418433
let parser_name = parser_name.into_bytes_with_nul();
419434

420435
let mut count: usize = 0;

rust/src/headless.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,13 @@ pub fn shutdown() {
101101
}
102102

103103
/// Prelued-postlued helper function (calls [`init`] and [`shutdown`] for you)
104-
/// ```rust
104+
/// ```no_run
105+
/// # use binaryninja::binaryview::BinaryViewExt;
105106
/// binaryninja::headless::script_helper(|| {
106-
/// binaryninja::load("/bin/cat")
107-
/// .expect("Couldn't open `/bin/cat`")
108-
/// .iter()
109-
/// .for_each(|func| println!(" `{}`", func.symbol().full_name()));
107+
/// let cat = binaryninja::load("/bin/cat").expect("Couldn't open `/bin/cat`");
108+
/// for function in cat.functions().iter() {
109+
/// println!(" `{}`", function.symbol().full_name());
110+
/// }
110111
/// });
111112
/// ```
112113
pub fn script_helper(func: fn()) {
@@ -124,7 +125,7 @@ impl Session {
124125
Self {}
125126
}
126127

127-
/// ```rust
128+
/// ```no_run
128129
/// let headless_session = binaryninja::headless::Session::new();
129130
///
130131
/// let bv = headless_session.load("/bin/cat").expect("Couldn't open `/bin/cat`");
@@ -133,7 +134,7 @@ impl Session {
133134
crate::load(filename)
134135
}
135136

136-
/// ```rust
137+
/// ```no_run
137138
/// let settings = [("analysis.linearSweep.autorun", false)].into();
138139
/// let headless_session = binaryninja::headless::Session::new();
139140
///

rust/src/interaction.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,10 @@ impl FormInputBuilder {
451451
///
452452
/// This API is flexible and works both in the UI via a pop-up dialog and on the command-line.
453453
///
454-
/// ```
455-
/// let responses = interaction::FormInputBuilder::new()
454+
/// ```no_run
455+
/// # use binaryninja::interaction::FormInputBuilder;
456+
/// # use binaryninja::interaction::FormResponses;
457+
/// let responses = FormInputBuilder::new()
456458
/// .text_field("First Name", None)
457459
/// .text_field("Last Name", None)
458460
/// .choice_field(
@@ -469,15 +471,19 @@ impl FormInputBuilder {
469471
/// .get_form_input("Form Title");
470472
///
471473
/// let food = match responses[2] {
472-
/// Index(0) => "Pizza",
473-
/// Index(1) => "Also Pizza",
474-
/// Index(2) => "Also Pizza",
475-
/// Index(3) => "Wrong Answer",
474+
/// FormResponses::Index(0) => "Pizza",
475+
/// FormResponses::Index(1) => "Also Pizza",
476+
/// FormResponses::Index(2) => "Also Pizza",
477+
/// FormResponses::Index(3) => "Wrong Answer",
476478
/// _ => panic!("This person doesn't like pizza?!?"),
477479
/// };
478480
///
479-
/// let interaction::FormResponses::String(last_name) = responses[0];
480-
/// let interaction::FormResponses::String(first_name) = responses[1];
481+
/// let FormResponses::String(last_name) = &responses[0] else {
482+
/// unreachable!()
483+
/// };
484+
/// let FormResponses::String(first_name) = &responses[1] else {
485+
/// unreachable!()
486+
/// };
481487
///
482488
/// println!("{} {} likes {}", &first_name, &last_name, food);
483489
/// ```

rust/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
//!
5050
//! Create a new library (`cargo new --lib <plugin-name>`) and include the following in your `Cargo.toml`:
5151
//!
52-
//! ```
52+
//! ```toml
5353
//! [lib]
5454
//! crate-type = ["cdylib"]
5555
//!
@@ -73,17 +73,19 @@
7373
//!
7474
//! ### `main.rs`
7575
//! Standalone binaries need to initialize Binary Ninja before they can work. You can do this through [`headless::Session`], [`headless::script_helper`], or [`headless::init()`] at start and [`headless::shutdown()`] at shutdown.
76-
//! ```rust
76+
//! ```no_run
7777
//! // This loads all the core architecture, platform, etc plugins
7878
//! // Standalone executables need to call this, but plugins do not
7979
//! let headless_session = binaryninja::headless::Session::new();
8080
//!
8181
//! println!("Loading binary...");
8282
//! let bv = headless_session.load("/bin/cat").expect("Couldn't open `/bin/cat`");
83+
//!
84+
//! // Your code here...
8385
//! ```
8486
//!
8587
//! ### `Cargo.toml`
86-
//! ```
88+
//! ```toml
8789
//! [dependencies]
8890
//! binaryninja = { git = "https://github.com/Vector35/binaryninja-api.git", branch = "dev"}
8991
//! ```
@@ -215,7 +217,7 @@ pub fn load<S: BnStrCompatible>(filename: S) -> Option<rc::Ref<binaryview::Binar
215217

216218
/// The main way to open and load files (with options) into Binary Ninja. Make sure you've properly initialized the core before calling this function. See [`crate::headless::init()`]
217219
///
218-
/// ```rust
220+
/// ```no_run
219221
/// let settings = [("analysis.linearSweep.autorun", false)].into();
220222
///
221223
/// let bv = binaryninja::load_with_options("/bin/cat", true, Some(settings))

rust/src/section.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@ impl Section {
7272

7373
/// You need to create a section builder, customize that section, then add it to a binary view:
7474
///
75-
/// ```
76-
/// bv.add_section(Section::new().align(4).entry_size(4))
75+
/// ```no_run
76+
/// # use binaryninja::section::Section;
77+
/// # use binaryninja::binaryview::BinaryViewExt;
78+
/// let bv = binaryninja::load("example").unwrap();
79+
/// bv.add_section(Section::builder("example", 0..1024).align(4).entry_size(4))
7780
/// ```
7881
pub fn builder<S: BnStrCompatible>(name: S, range: Range<u64>) -> SectionBuilder<S> {
7982
SectionBuilder::new(name, range)

rust/src/segment.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,11 @@ impl Segment {
117117

118118
/// You need to create a segment builder, customize that segment, then add it to a binary view:
119119
///
120-
/// ```
121-
/// bv.add_segment(Segment::new().align(4).entry_size(4))
120+
/// ```no_run
121+
/// # use binaryninja::segment::Segment;
122+
/// # use binaryninja::binaryview::BinaryViewExt;
123+
/// let bv = binaryninja::load("example").unwrap();
124+
/// bv.add_segment(Segment::builder(0..0x1000).writable(true).readable(true))
122125
/// ```
123126
pub fn builder(ea_range: Range<u64>) -> SegmentBuilder {
124127
SegmentBuilder::new(ea_range)

rust/src/symbol.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,10 @@ impl Symbol {
231231

232232
/// To create a new symbol, you need to create a symbol builder, customize that symbol, then add `SymbolBuilder::create` it into a `Ref<Symbol>`:
233233
///
234-
/// ```
235-
/// Symbol::new().short_name("hello").full_name("hello").create();
234+
/// ```no_run
235+
/// # use binaryninja::symbol::Symbol;
236+
/// # use binaryninja::symbol::SymbolType;
237+
/// Symbol::builder(SymbolType::Data, "hello", 0x1337).short_name("hello").full_name("hello").create();
236238
/// ```
237239
pub fn builder(ty: SymbolType, raw_name: &str, addr: u64) -> SymbolBuilder {
238240
SymbolBuilder::new(ty, raw_name, addr)

0 commit comments

Comments
 (0)