diff options
| author | Mason Reed <mason@vector35.com> | 2025-05-07 19:22:21 -0400 |
|---|---|---|
| committer | Mason Reed <35282038+emesare@users.noreply.github.com> | 2025-05-12 17:45:24 -0400 |
| commit | 2f214f6c9935e8ce8df4732cde44a540a003258c (patch) | |
| tree | 6fe319433ef0d2ad75fcc58a50eaa632bb627ec9 /rust/src/custom_binary_view.rs | |
| parent | b4cf0be8816182c9efca037e27e9439482f8bf36 (diff) | |
[Rust] Reduce usage of `IntoCStr` in function signatures
This is being done to reduce complexity in function signatures, specifically many of the strings we are passing ultimately should be new types themselves instead of "just strings", things such as type ids.
Another place which was confusing was dealing with filesystem related APIs, this commit turns most of those params into a stricter `Path` type.
This is bringing the rust api more inline with both python and C++, where the wrapper eagerly converts the string into the languages standard string type.
Special consideration must be made for symbols or other possible non utf-8 objects.
This commit will be followed up with one that adds the `IntoCStr` bound on API's we want to keep as invalid utf-8 so we can for example, get section by name on a section with invalid utf-8.
Diffstat (limited to 'rust/src/custom_binary_view.rs')
| -rw-r--r-- | rust/src/custom_binary_view.rs | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/rust/src/custom_binary_view.rs b/rust/src/custom_binary_view.rs index 7e5c0a24..f809f251 100644 --- a/rust/src/custom_binary_view.rs +++ b/rust/src/custom_binary_view.rs @@ -39,9 +39,8 @@ use crate::Endianness; /// the core. The `BinaryViewType` argument passed to `constructor` is the object that the /// `AsRef<BinaryViewType>` /// implementation of the `CustomBinaryViewType` must return. -pub fn register_view_type<S, T, F>(name: S, long_name: S, constructor: F) -> &'static T +pub fn register_view_type<T, F>(name: &str, long_name: &str, constructor: F) -> &'static T where - S: IntoCStr, T: CustomBinaryViewType, F: FnOnce(BinaryViewType) -> T, { @@ -359,7 +358,7 @@ impl BinaryViewType { } /// Looks up a BinaryViewType by its short name - pub fn by_name<N: IntoCStr>(name: N) -> Result<Self> { + pub fn by_name(name: &str) -> Result<Self> { let bytes = name.to_cstr(); let handle = unsafe { BNGetBinaryViewTypeByName(bytes.as_ref().as_ptr() as *const _) }; match handle.is_null() { |
