Skip to content

Commit 62e22b3

Browse files
committed
[Rust] Improve API surrounding binary view type libraries
1 parent 62f2c7f commit 62e22b3

1 file changed

Lines changed: 27 additions & 26 deletions

File tree

rust/src/binary_view.rs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,9 +2145,9 @@ pub trait BinaryViewExt: BinaryViewBase {
21452145
NonNull::new(result).map(|h| unsafe { TypeLibrary::ref_from_raw(h) })
21462146
}
21472147

2148-
/// Should be called by custom py:py:class:`BinaryView` implementations
2149-
/// when they have successfully imported an object from a type library (eg a symbol's type).
2150-
/// Values recorded with this function will then be queryable via [BinaryViewExt::lookup_imported_object_library].
2148+
/// Should be called by custom [`BinaryView`] implementations when they have successfully
2149+
/// imported an object from a type library (eg a symbol's type). Values recorded with this
2150+
/// function will then be queryable via [`BinaryViewExt::lookup_imported_object_library`].
21512151
///
21522152
/// * `lib` - Type Library containing the imported type
21532153
/// * `name` - Name of the object in the type library
@@ -2173,23 +2173,23 @@ pub trait BinaryViewExt: BinaryViewBase {
21732173
QualifiedName::free_raw(raw_name);
21742174
}
21752175

2176-
/// Recursively imports a type from the specified type library, or, if
2177-
/// no library was explicitly provided, the first type library associated with the current [BinaryView]
2178-
/// that provides the name requested.
2176+
/// Recursively imports a type from the specified type library, or, if no library was
2177+
/// explicitly provided, the first type library associated with the current [`BinaryView`] that
2178+
/// provides the name requested.
21792179
///
2180-
/// This may have the impact of loading other type libraries as dependencies on other type libraries are lazily resolved
2181-
/// when references to types provided by them are first encountered.
2180+
/// This may have the impact of loading other type libraries as dependencies on other type
2181+
/// libraries are lazily resolved when references to types provided by them are first encountered.
21822182
///
2183-
/// Note that the name actually inserted into the view may not match the name as it exists in the type library in
2184-
/// the event of a name conflict. To aid in this, the [Type] object returned is a `NamedTypeReference` to
2185-
/// the deconflicted name used.
2183+
/// Note that the name actually inserted into the view may not match the name as it exists in
2184+
/// the type library in the event of a name conflict. To aid in this, the [`Type`] object
2185+
/// returned is a `NamedTypeReference` to the deconflicted name used.
21862186
fn import_type_library<T: Into<QualifiedName>>(
21872187
&self,
21882188
name: T,
2189-
mut lib: Option<TypeLibrary>,
2189+
lib: Option<&TypeLibrary>,
21902190
) -> Option<Ref<Type>> {
21912191
let mut lib_ref = lib
2192-
.as_mut()
2192+
.as_ref()
21932193
.map(|l| unsafe { l.as_raw() } as *mut _)
21942194
.unwrap_or(std::ptr::null_mut());
21952195
let mut raw_name = QualifiedName::into_raw(name.into());
@@ -2200,22 +2200,23 @@ pub trait BinaryViewExt: BinaryViewBase {
22002200
(!result.is_null()).then(|| unsafe { Type::ref_from_raw(result) })
22012201
}
22022202

2203-
/// Recursively imports an object from the specified type library, or, if
2204-
/// no library was explicitly provided, the first type library associated with the current [BinaryView]
2205-
/// that provides the name requested.
2203+
/// Recursively imports an object (function) from the specified type library, or, if no library was
2204+
/// explicitly provided, the first type library associated with the current [`BinaryView`] that
2205+
/// provides the name requested.
22062206
///
2207-
/// This may have the impact of loading other type libraries as dependencies on other type libraries are lazily resolved
2208-
/// when references to types provided by them are first encountered.
2207+
/// This may have the impact of loading other type libraries as dependencies on other type
2208+
/// libraries are lazily resolved when references to types provided by them are first encountered.
22092209
///
2210-
/// .. note:: If you are implementing a custom BinaryView and use this method to import object types,
2211-
/// you should then call [BinaryViewExt::record_imported_object_library] with the details of where the object is located.
2210+
/// NOTE: If you are implementing a custom [`BinaryView`] and use this method to import object types,
2211+
/// you should then call [BinaryViewExt::record_imported_object_library] with the details of
2212+
/// where the object is located.
22122213
fn import_type_object<T: Into<QualifiedName>>(
22132214
&self,
22142215
name: T,
2215-
mut lib: Option<TypeLibrary>,
2216+
lib: Option<&TypeLibrary>,
22162217
) -> Option<Ref<Type>> {
22172218
let mut lib_ref = lib
2218-
.as_mut()
2219+
.as_ref()
22192220
.map(|l| unsafe { l.as_raw() } as *mut _)
22202221
.unwrap_or(std::ptr::null_mut());
22212222
let mut raw_name = QualifiedName::into_raw(name.into());
@@ -2226,15 +2227,15 @@ pub trait BinaryViewExt: BinaryViewBase {
22262227
(!result.is_null()).then(|| unsafe { Type::ref_from_raw(result) })
22272228
}
22282229

2229-
/// Recursively imports a type interface given its GUID.
2230+
/// Recursively imports a [`Type`] given its GUID from available type libraries.
22302231
fn import_type_by_guid(&self, guid: &str) -> Option<Ref<Type>> {
22312232
let guid = guid.to_cstr();
22322233
let result =
22332234
unsafe { BNBinaryViewImportTypeLibraryTypeByGuid(self.as_ref().handle, guid.as_ptr()) };
22342235
(!result.is_null()).then(|| unsafe { Type::ref_from_raw(result) })
22352236
}
22362237

2237-
/// Recursively exports `type_obj` into `lib` as a type with name `name`
2238+
/// Recursively exports `type_obj` into `lib` as a type with name `name`.
22382239
///
22392240
/// As other referenced types are encountered, they are either copied into the destination type library or
22402241
/// else the type library that provided the referenced type is added as a dependency for the destination library.
@@ -2256,10 +2257,10 @@ pub trait BinaryViewExt: BinaryViewBase {
22562257
QualifiedName::free_raw(raw_name);
22572258
}
22582259

2259-
/// Recursively exports `type_obj` into `lib` as a type with name `name`
2260+
/// Recursively exports `type_obj` into `lib` as a type with name `name`.
22602261
///
22612262
/// As other referenced types are encountered, they are either copied into the destination type library or
2262-
/// else the type library that provided the referenced type is added as a dependency for the destination library.
2263+
/// else the type library that provided the referenced type is added as a dependency for the destination library.
22632264
fn export_object_to_library<T: Into<QualifiedName>>(
22642265
&self,
22652266
lib: &TypeLibrary,

0 commit comments

Comments
 (0)