summaryrefslogtreecommitdiff
path: root/rust/src
diff options
context:
space:
mode:
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/architecture.rs8
-rw-r--r--rust/src/background_task.rs4
-rw-r--r--rust/src/binary_view.rs85
-rw-r--r--rust/src/binary_view/memory_map.rs24
-rw-r--r--rust/src/calling_convention.rs3
-rw-r--r--rust/src/collaboration.rs21
-rw-r--r--rust/src/collaboration/changeset.rs2
-rw-r--r--rust/src/collaboration/file.rs42
-rw-r--r--rust/src/collaboration/folder.rs4
-rw-r--r--rust/src/collaboration/group.rs7
-rw-r--r--rust/src/collaboration/merge.rs8
-rw-r--r--rust/src/collaboration/project.rs97
-rw-r--r--rust/src/collaboration/remote.rs74
-rw-r--r--rust/src/collaboration/snapshot.rs4
-rw-r--r--rust/src/collaboration/sync.rs64
-rw-r--r--rust/src/collaboration/user.rs4
-rw-r--r--rust/src/command.rs21
-rw-r--r--rust/src/component.rs2
-rw-r--r--rust/src/custom_binary_view.rs5
-rw-r--r--rust/src/data_buffer.rs3
-rw-r--r--rust/src/database.rs19
-rw-r--r--rust/src/database/kvs.rs6
-rw-r--r--rust/src/database/snapshot.rs2
-rw-r--r--rust/src/debuginfo.rs57
-rw-r--r--rust/src/demangle.rs28
-rw-r--r--rust/src/disassembly.rs8
-rw-r--r--rust/src/download_provider.rs25
-rw-r--r--rust/src/enterprise.rs16
-rw-r--r--rust/src/external_library.rs2
-rw-r--r--rust/src/file_metadata.rs46
-rw-r--r--rust/src/function.rs10
-rw-r--r--rust/src/headless.rs2
-rw-r--r--rust/src/high_level_il/operation.rs4
-rw-r--r--rust/src/lib.rs25
-rw-r--r--rust/src/medium_level_il/function.rs16
-rw-r--r--rust/src/metadata.rs6
-rw-r--r--rust/src/platform.rs13
-rw-r--r--rust/src/project.rs197
-rw-r--r--rust/src/project/file.rs9
-rw-r--r--rust/src/project/folder.rs12
-rw-r--r--rust/src/relocation.rs3
-rw-r--r--rust/src/render_layer.rs6
-rw-r--r--rust/src/repository.rs14
-rw-r--r--rust/src/repository/manager.rs7
-rw-r--r--rust/src/repository/plugin.rs11
-rw-r--r--rust/src/secrets_provider.rs10
-rw-r--r--rust/src/settings.rs110
-rw-r--r--rust/src/tags.rs12
-rw-r--r--rust/src/type_archive.rs139
-rw-r--r--rust/src/type_container.rs35
-rw-r--r--rust/src/type_library.rs34
-rw-r--r--rust/src/type_parser.rs6
-rw-r--r--rust/src/type_printer.rs8
-rw-r--r--rust/src/types.rs85
-rw-r--r--rust/src/websocket/client.rs25
-rw-r--r--rust/src/websocket/provider.rs2
-rw-r--r--rust/src/worker_thread.rs6
-rw-r--r--rust/src/workflow.rs50
58 files changed, 651 insertions, 897 deletions
diff --git a/rust/src/architecture.rs b/rust/src/architecture.rs
index c02fc717..a48cbce3 100644
--- a/rust/src/architecture.rs
+++ b/rust/src/architecture.rs
@@ -1953,7 +1953,7 @@ macro_rules! cc_func {
/// Contains helper methods for all types implementing 'Architecture'
pub trait ArchitectureExt: Architecture {
- fn register_by_name<S: IntoCStr>(&self, name: S) -> Option<Self::Register> {
+ fn register_by_name(&self, name: &str) -> Option<Self::Register> {
let name = name.to_cstr();
match unsafe { BNGetArchitectureRegisterByName(self.as_ref().handle, name.as_ptr()) } {
@@ -2029,9 +2029,8 @@ pub trait ArchitectureExt: Architecture {
}
}
- fn register_relocation_handler<S, R, F>(&self, name: S, func: F)
+ fn register_relocation_handler<R, F>(&self, name: &str, func: F)
where
- S: IntoCStr,
R: 'static
+ RelocationHandler<Handle = CustomRelocationHandlerHandle<R>>
+ Send
@@ -2052,9 +2051,8 @@ pub trait ArchitectureExt: Architecture {
impl<T: Architecture> ArchitectureExt for T {}
-pub fn register_architecture<S, A, F>(name: S, func: F) -> &'static A
+pub fn register_architecture<A, F>(name: &str, func: F) -> &'static A
where
- S: IntoCStr,
A: 'static + Architecture<Handle = CustomArchitectureHandle<A>> + Send + Sync + Sized,
F: FnOnce(CustomArchitectureHandle<A>, CoreArchitecture) -> A,
{
diff --git a/rust/src/background_task.rs b/rust/src/background_task.rs
index b0537fa8..ea1e3b0d 100644
--- a/rust/src/background_task.rs
+++ b/rust/src/background_task.rs
@@ -43,7 +43,7 @@ impl BackgroundTask {
Self { handle }
}
- pub fn new<S: IntoCStr>(initial_text: S, can_cancel: bool) -> Ref<Self> {
+ pub fn new(initial_text: &str, can_cancel: bool) -> Ref<Self> {
let text = initial_text.to_cstr();
let handle = unsafe { BNBeginBackgroundTask(text.as_ptr(), can_cancel) };
// We should always be returned a valid task.
@@ -75,7 +75,7 @@ impl BackgroundTask {
unsafe { BnString::into_string(BNGetBackgroundTaskProgressText(self.handle)) }
}
- pub fn set_progress_text<S: IntoCStr>(&self, text: S) {
+ pub fn set_progress_text(&self, text: &str) {
let progress_text = text.to_cstr();
unsafe { BNSetBackgroundTaskProgressText(self.handle, progress_text.as_ptr()) }
}
diff --git a/rust/src/binary_view.rs b/rust/src/binary_view.rs
index 7259efbf..35383f0b 100644
--- a/rust/src/binary_view.rs
+++ b/rust/src/binary_view.rs
@@ -266,7 +266,7 @@ pub trait BinaryViewExt: BinaryViewBase {
unsafe { BNGetEndOffset(self.as_ref().handle) }
}
- fn add_analysis_option(&self, name: impl IntoCStr) {
+ fn add_analysis_option(&self, name: &str) {
let name = name.to_cstr();
unsafe { BNAddAnalysisOption(self.as_ref().handle, name.as_ptr()) }
}
@@ -399,7 +399,7 @@ pub trait BinaryViewExt: BinaryViewBase {
}
}
- fn symbol_by_raw_name<S: IntoCStr>(&self, raw_name: S) -> Option<Ref<Symbol>> {
+ fn symbol_by_raw_name(&self, raw_name: impl IntoCStr) -> Option<Ref<Symbol>> {
let raw_name = raw_name.to_cstr();
unsafe {
@@ -424,7 +424,7 @@ pub trait BinaryViewExt: BinaryViewBase {
}
}
- fn symbols_by_name<S: IntoCStr>(&self, name: S) -> Array<Symbol> {
+ fn symbols_by_name(&self, name: impl IntoCStr) -> Array<Symbol> {
let raw_name = name.to_cstr();
unsafe {
@@ -585,10 +585,10 @@ pub trait BinaryViewExt: BinaryViewBase {
}
}
- fn define_auto_type<T: Into<QualifiedName>, S: IntoCStr>(
+ fn define_auto_type<T: Into<QualifiedName>>(
&self,
name: T,
- source: S,
+ source: &str,
type_obj: &Type,
) -> QualifiedName {
let mut raw_name = QualifiedName::into_raw(name.into());
@@ -602,10 +602,10 @@ pub trait BinaryViewExt: BinaryViewBase {
QualifiedName::from_owned_raw(name_handle)
}
- fn define_auto_type_with_id<T: Into<QualifiedName>, S: IntoCStr>(
+ fn define_auto_type_with_id<T: Into<QualifiedName>>(
&self,
name: T,
- id: S,
+ id: &str,
type_obj: &Type,
) -> QualifiedName {
let mut raw_name = QualifiedName::into_raw(name.into());
@@ -712,7 +712,7 @@ pub trait BinaryViewExt: BinaryViewBase {
}
}
- fn undefine_auto_type<S: IntoCStr>(&self, id: S) {
+ fn undefine_auto_type(&self, id: &str) {
let id_str = id.to_cstr();
unsafe {
BNUndefineAnalysisType(self.as_ref().handle, id_str.as_ref().as_ptr() as *const _);
@@ -763,7 +763,7 @@ pub trait BinaryViewExt: BinaryViewBase {
}
}
- fn type_by_id<S: IntoCStr>(&self, id: S) -> Option<Ref<Type>> {
+ fn type_by_id(&self, id: &str) -> Option<Ref<Type>> {
let id_str = id.to_cstr();
unsafe {
let type_handle = BNGetAnalysisTypeById(self.as_ref().handle, id_str.as_ptr());
@@ -774,7 +774,7 @@ pub trait BinaryViewExt: BinaryViewBase {
}
}
- fn type_name_by_id<S: IntoCStr>(&self, id: S) -> Option<QualifiedName> {
+ fn type_name_by_id(&self, id: &str) -> Option<QualifiedName> {
let id_str = id.to_cstr();
unsafe {
let name_handle = BNGetAnalysisTypeNameById(self.as_ref().handle, id_str.as_ptr());
@@ -787,12 +787,12 @@ pub trait BinaryViewExt: BinaryViewBase {
}
}
- fn type_id_by_name<T: Into<QualifiedName>>(&self, name: T) -> Option<BnString> {
+ fn type_id_by_name<T: Into<QualifiedName>>(&self, name: T) -> Option<String> {
let mut raw_name = QualifiedName::into_raw(name.into());
unsafe {
let id_cstr = BNGetAnalysisTypeId(self.as_ref().handle, &mut raw_name);
QualifiedName::free_raw(raw_name);
- let id = BnString::from_raw(id_cstr);
+ let id = BnString::into_string(id_cstr);
match id.is_empty() {
true => None,
false => Some(id),
@@ -871,7 +871,7 @@ pub trait BinaryViewExt: BinaryViewBase {
section.create(self.as_ref());
}
- fn remove_auto_section<S: IntoCStr>(&self, name: S) {
+ fn remove_auto_section(&self, name: &str) {
let raw_name = name.to_cstr();
let raw_name_ptr = raw_name.as_ptr();
unsafe {
@@ -879,7 +879,7 @@ pub trait BinaryViewExt: BinaryViewBase {
}
}
- fn remove_user_section<S: IntoCStr>(&self, name: S) {
+ fn remove_user_section(&self, name: &str) {
let raw_name = name.to_cstr();
let raw_name_ptr = raw_name.as_ptr();
unsafe {
@@ -887,7 +887,7 @@ pub trait BinaryViewExt: BinaryViewBase {
}
}
- fn section_by_name<S: IntoCStr>(&self, name: S) -> Option<Ref<Section>> {
+ fn section_by_name(&self, name: &str) -> Option<Ref<Section>> {
unsafe {
let raw_name = name.to_cstr();
let name_ptr = raw_name.as_ptr();
@@ -1103,14 +1103,14 @@ pub trait BinaryViewExt: BinaryViewBase {
unsafe { BNApplyDebugInfo(self.as_ref().handle, debug_info.handle) }
}
- fn show_graph_report<S: IntoCStr>(&self, raw_name: S, graph: &FlowGraph) {
+ fn show_graph_report(&self, raw_name: &str, graph: &FlowGraph) {
let raw_name = raw_name.to_cstr();
unsafe {
BNShowGraphReport(self.as_ref().handle, raw_name.as_ptr(), graph.handle);
}
}
- fn load_settings<S: IntoCStr>(&self, view_type_name: S) -> Result<Ref<Settings>> {
+ fn load_settings(&self, view_type_name: &str) -> Result<Ref<Settings>> {
let view_type_name = view_type_name.to_cstr();
let settings_handle =
unsafe { BNBinaryViewGetLoadSettings(self.as_ref().handle, view_type_name.as_ptr()) };
@@ -1122,7 +1122,7 @@ pub trait BinaryViewExt: BinaryViewBase {
}
}
- fn set_load_settings<S: IntoCStr>(&self, view_type_name: S, settings: &Settings) {
+ fn set_load_settings(&self, view_type_name: &str, settings: &Settings) {
let view_type_name = view_type_name.to_cstr();
unsafe {
@@ -1139,7 +1139,7 @@ pub trait BinaryViewExt: BinaryViewBase {
/// # Arguments
/// * `name` - the name for the tag
/// * `icon` - the icon (recommended 1 emoji or 2 chars) for the tag
- fn create_tag_type<N: IntoCStr, I: IntoCStr>(&self, name: N, icon: I) -> Ref<TagType> {
+ fn create_tag_type(&self, name: &str, icon: &str) -> Ref<TagType> {
let tag_type = TagType::create(self.as_ref(), name, icon);
unsafe {
BNAddTagType(self.as_ref().handle, tag_type.handle);
@@ -1153,7 +1153,7 @@ pub trait BinaryViewExt: BinaryViewBase {
}
/// Get a tag type by its name.
- fn tag_type_by_name<S: IntoCStr>(&self, name: S) -> Option<Ref<TagType>> {
+ fn tag_type_by_name(&self, name: &str) -> Option<Ref<TagType>> {
let name = name.to_cstr();
unsafe {
let handle = BNGetTagType(self.as_ref().handle, name.as_ptr());
@@ -1167,7 +1167,7 @@ pub trait BinaryViewExt: BinaryViewBase {
/// Get a tag by its id.
///
/// Note this does not tell you anything about where it is used.
- fn tag_by_id<S: IntoCStr>(&self, id: S) -> Option<Ref<Tag>> {
+ fn tag_by_id(&self, id: &str) -> Option<Ref<Tag>> {
let id = id.to_cstr();
unsafe {
let handle = BNGetTag(self.as_ref().handle, id.as_ptr());
@@ -1181,7 +1181,7 @@ pub trait BinaryViewExt: BinaryViewBase {
/// Creates and adds a tag to an address
///
/// User tag creations will be added to the undo buffer
- fn add_tag<S: IntoCStr>(&self, addr: u64, t: &TagType, data: S, user: bool) {
+ fn add_tag(&self, addr: u64, t: &TagType, data: &str, user: bool) {
let tag = Tag::new(t, data);
unsafe { BNAddTag(self.as_ref().handle, tag.handle, user) }
@@ -1204,11 +1204,11 @@ pub trait BinaryViewExt: BinaryViewBase {
unsafe { BNRemoveUserDataTag(self.as_ref().handle, addr, tag.handle) }
}
- fn comment_at(&self, addr: u64) -> Option<BnString> {
+ fn comment_at(&self, addr: u64) -> Option<String> {
unsafe {
let comment_raw = BNGetGlobalCommentForAddress(self.as_ref().handle, addr);
match comment_raw.is_null() {
- false => Some(BnString::from_raw(comment_raw)),
+ false => Some(BnString::into_string(comment_raw)),
true => None,
}
}
@@ -1218,7 +1218,7 @@ pub trait BinaryViewExt: BinaryViewBase {
///
/// NOTE: This is different from setting a comment at the function-level. To set a comment in a
/// function use [`Function::set_comment_at`]
- fn set_comment_at(&self, addr: u64, comment: impl IntoCStr) {
+ fn set_comment_at(&self, addr: u64, comment: &str) {
let comment_raw = comment.to_cstr();
unsafe { BNSetGlobalCommentForAddress(self.as_ref().handle, addr, comment_raw.as_ptr()) }
}
@@ -1271,7 +1271,7 @@ pub trait BinaryViewExt: BinaryViewBase {
result
}
- fn query_metadata<S: IntoCStr>(&self, key: S) -> Option<Ref<Metadata>> {
+ fn query_metadata(&self, key: &str) -> Option<Ref<Metadata>> {
let key = key.to_cstr();
let value: *mut BNMetadata =
unsafe { BNBinaryViewQueryMetadata(self.as_ref().handle, key.as_ptr()) };
@@ -1282,7 +1282,7 @@ pub trait BinaryViewExt: BinaryViewBase {
}
}
- fn get_metadata<T, S: IntoCStr>(&self, key: S) -> Option<Result<T>>
+ fn get_metadata<T>(&self, key: &str) -> Option<Result<T>>
where
T: for<'a> TryFrom<&'a Metadata>,
{
@@ -1290,7 +1290,7 @@ pub trait BinaryViewExt: BinaryViewBase {
.map(|md| T::try_from(md.as_ref()).map_err(|_| ()))
}
- fn store_metadata<V, S: IntoCStr>(&self, key: S, value: V, is_auto: bool)
+ fn store_metadata<V>(&self, key: &str, value: V, is_auto: bool)
where
V: Into<Ref<Metadata>>,
{
@@ -1306,7 +1306,7 @@ pub trait BinaryViewExt: BinaryViewBase {
};
}
- fn remove_metadata<S: IntoCStr>(&self, key: S) {
+ fn remove_metadata(&self, key: &str) {
let key = key.to_cstr();
unsafe { BNBinaryViewRemoveMetadata(self.as_ref().handle, key.as_ptr()) };
}
@@ -1432,7 +1432,7 @@ pub trait BinaryViewExt: BinaryViewBase {
.collect()
}
- fn component_by_guid<S: IntoCStr>(&self, guid: S) -> Option<Ref<Component>> {
+ fn component_by_guid(&self, guid: &str) -> Option<Ref<Component>> {
let name = guid.to_cstr();
let result = unsafe { BNGetComponentByGuid(self.as_ref().handle, name.as_ptr()) };
NonNull::new(result).map(|h| unsafe { Component::ref_from_raw(h) })
@@ -1443,7 +1443,7 @@ pub trait BinaryViewExt: BinaryViewBase {
NonNull::new(result).map(|h| unsafe { Component::ref_from_raw(h) })
}
- fn component_by_path<P: IntoCStr>(&self, path: P) -> Option<Ref<Component>> {
+ fn component_by_path(&self, path: &str) -> Option<Ref<Component>> {
let path = path.to_cstr();
let result = unsafe { BNGetComponentByPath(self.as_ref().handle, path.as_ptr()) };
NonNull::new(result).map(|h| unsafe { Component::ref_from_raw(h) })
@@ -1453,7 +1453,7 @@ pub trait BinaryViewExt: BinaryViewBase {
unsafe { BNRemoveComponent(self.as_ref().handle, component.handle.as_ptr()) }
}
- fn remove_component_by_guid<P: IntoCStr>(&self, guid: P) -> bool {
+ fn remove_component_by_guid(&self, guid: &str) -> bool {
let path = guid.to_cstr();
unsafe { BNRemoveComponentByGuid(self.as_ref().handle, path.as_ptr()) }
}
@@ -1476,7 +1476,7 @@ pub trait BinaryViewExt: BinaryViewBase {
unsafe { Array::new(result, count, ()) }
}
- fn external_library<S: IntoCStr>(&self, name: S) -> Option<Ref<ExternalLibrary>> {
+ fn external_library(&self, name: &str) -> Option<Ref<ExternalLibrary>> {
let name_ptr = name.to_cstr();
let result =
unsafe { BNBinaryViewGetExternalLibrary(self.as_ref().handle, name_ptr.as_ptr()) };
@@ -1484,14 +1484,14 @@ pub trait BinaryViewExt: BinaryViewBase {
Some(unsafe { ExternalLibrary::ref_from_raw(result_ptr) })
}
- fn remove_external_library<S: IntoCStr>(&self, name: S) {
+ fn remove_external_library(&self, name: &str) {
let name_ptr = name.to_cstr();
unsafe { BNBinaryViewRemoveExternalLibrary(self.as_ref().handle, name_ptr.as_ptr()) };
}
- fn add_external_library<S: IntoCStr>(
+ fn add_external_library(
&self,
- name: S,
+ name: &str,
backing_file: Option<&ProjectFile>,
auto: bool,
) -> Option<Ref<ExternalLibrary>> {
@@ -1531,11 +1531,11 @@ pub trait BinaryViewExt: BinaryViewBase {
}
// TODO: This is awful, rewrite this.
- fn add_external_location<S: IntoCStr>(
+ fn add_external_location(
&self,
symbol: &Symbol,
library: &ExternalLibrary,
- target_symbol_name: S,
+ target_symbol_name: &str,
target_address: Option<u64>,
target_is_auto: bool,
) -> Option<Ref<ExternalLocation>> {
@@ -1589,7 +1589,7 @@ pub trait BinaryViewExt: BinaryViewBase {
unsafe { BNAddBinaryViewTypeLibrary(self.as_ref().handle, library.as_raw()) }
}
- fn type_library_by_name<S: IntoCStr>(&self, name: S) -> Option<TypeLibrary> {
+ fn type_library_by_name(&self, name: &str) -> Option<TypeLibrary> {
let name = name.to_cstr();
let result = unsafe { BNGetBinaryViewTypeLibrary(self.as_ref().handle, name.as_ptr()) };
NonNull::new(result).map(|h| unsafe { TypeLibrary::from_raw(h) })
@@ -1677,12 +1677,7 @@ pub trait BinaryViewExt: BinaryViewBase {
}
/// Recursively imports a type interface given its GUID.
- ///
- /// .. note:: To support this type of lookup a type library must have
- /// contain a metadata key called "type_guids" which is a map
- /// Dict[string_guid, string_type_name] or
- /// Dict[string_guid, Tuple[string_type_name, type_library_name]]
- fn import_type_by_guid<S: IntoCStr>(&self, guid: S) -> Option<Ref<Type>> {
+ fn import_type_by_guid(&self, guid: &str) -> Option<Ref<Type>> {
let guid = guid.to_cstr();
let result =
unsafe { BNBinaryViewImportTypeLibraryTypeByGuid(self.as_ref().handle, guid.as_ptr()) };
diff --git a/rust/src/binary_view/memory_map.rs b/rust/src/binary_view/memory_map.rs
index ad7c8ea1..28b52369 100644
--- a/rust/src/binary_view/memory_map.rs
+++ b/rust/src/binary_view/memory_map.rs
@@ -42,7 +42,7 @@ impl MemoryMap {
pub fn add_binary_memory_region(
&mut self,
- name: impl IntoCStr,
+ name: &str,
start: u64,
view: &BinaryView,
segment_flags: Option<SegmentFlags>,
@@ -61,7 +61,7 @@ impl MemoryMap {
pub fn add_data_memory_region(
&mut self,
- name: impl IntoCStr,
+ name: &str,
start: u64,
data: &DataBuffer,
segment_flags: Option<SegmentFlags>,
@@ -80,7 +80,7 @@ impl MemoryMap {
pub fn add_remote_memory_region(
&mut self,
- name: impl IntoCStr,
+ name: &str,
start: u64,
accessor: &mut FileAccessor,
segment_flags: Option<SegmentFlags>,
@@ -97,7 +97,7 @@ impl MemoryMap {
}
}
- pub fn remove_memory_region(&mut self, name: impl IntoCStr) -> bool {
+ pub fn remove_memory_region(&mut self, name: &str) -> bool {
let name_raw = name.to_cstr();
unsafe { BNRemoveMemoryRegion(self.view.handle, name_raw.as_ptr()) }
}
@@ -109,44 +109,44 @@ impl MemoryMap {
}
}
- pub fn memory_region_flags(&self, name: impl IntoCStr) -> SegmentFlags {
+ pub fn memory_region_flags(&self, name: &str) -> SegmentFlags {
let name_raw = name.to_cstr();
let flags_raw = unsafe { BNGetMemoryRegionFlags(self.view.handle, name_raw.as_ptr()) };
SegmentFlags::from_raw(flags_raw)
}
- pub fn set_memory_region_flags(&mut self, name: impl IntoCStr, flags: SegmentFlags) -> bool {
+ pub fn set_memory_region_flags(&mut self, name: &str, flags: SegmentFlags) -> bool {
let name_raw = name.to_cstr();
unsafe { BNSetMemoryRegionFlags(self.view.handle, name_raw.as_ptr(), flags.into_raw()) }
}
- pub fn is_memory_region_enabled(&self, name: impl IntoCStr) -> bool {
+ pub fn is_memory_region_enabled(&self, name: &str) -> bool {
let name_raw = name.to_cstr();
unsafe { BNIsMemoryRegionEnabled(self.view.handle, name_raw.as_ptr()) }
}
- pub fn set_memory_region_enabled(&mut self, name: impl IntoCStr, enabled: bool) -> bool {
+ pub fn set_memory_region_enabled(&mut self, name: &str, enabled: bool) -> bool {
let name_raw = name.to_cstr();
unsafe { BNSetMemoryRegionEnabled(self.view.handle, name_raw.as_ptr(), enabled) }
}
// TODO: Should we just call this is_memory_region_relocatable?
- pub fn is_memory_region_rebaseable(&self, name: impl IntoCStr) -> bool {
+ pub fn is_memory_region_rebaseable(&self, name: &str) -> bool {
let name_raw = name.to_cstr();
unsafe { BNIsMemoryRegionRebaseable(self.view.handle, name_raw.as_ptr()) }
}
- pub fn set_memory_region_rebaseable(&mut self, name: impl IntoCStr, enabled: bool) -> bool {
+ pub fn set_memory_region_rebaseable(&mut self, name: &str, enabled: bool) -> bool {
let name_raw = name.to_cstr();
unsafe { BNSetMemoryRegionRebaseable(self.view.handle, name_raw.as_ptr(), enabled) }
}
- pub fn memory_region_fill(&self, name: impl IntoCStr) -> u8 {
+ pub fn memory_region_fill(&self, name: &str) -> u8 {
let name_raw = name.to_cstr();
unsafe { BNGetMemoryRegionFill(self.view.handle, name_raw.as_ptr()) }
}
- pub fn set_memory_region_fill(&mut self, name: impl IntoCStr, fill: u8) -> bool {
+ pub fn set_memory_region_fill(&mut self, name: &str, fill: u8) -> bool {
let name_raw = name.to_cstr();
unsafe { BNSetMemoryRegionFill(self.view.handle, name_raw.as_ptr(), fill) }
}
diff --git a/rust/src/calling_convention.rs b/rust/src/calling_convention.rs
index 90af3aa8..04d85396 100644
--- a/rust/src/calling_convention.rs
+++ b/rust/src/calling_convention.rs
@@ -55,10 +55,9 @@ pub trait CallingConvention: Sync {
fn are_argument_registers_used_for_var_args(&self) -> bool;
}
-pub fn register_calling_convention<A, N, C>(arch: &A, name: N, cc: C) -> Ref<CoreCallingConvention>
+pub fn register_calling_convention<A, C>(arch: &A, name: &str, cc: C) -> Ref<CoreCallingConvention>
where
A: Architecture,
- N: IntoCStr,
C: 'static + CallingConvention,
{
struct CustomCallingConventionContext<C>
diff --git a/rust/src/collaboration.rs b/rust/src/collaboration.rs
index 9a97a0e8..0a17d94c 100644
--- a/rust/src/collaboration.rs
+++ b/rust/src/collaboration.rs
@@ -73,21 +73,21 @@ pub fn known_remotes() -> Array<Remote> {
}
/// Get Remote by unique `id`
-pub fn get_remote_by_id<S: IntoCStr>(id: S) -> Option<Ref<Remote>> {
+pub fn get_remote_by_id(id: &str) -> Option<Ref<Remote>> {
let id = id.to_cstr();
let value = unsafe { BNCollaborationGetRemoteById(id.as_ptr()) };
NonNull::new(value).map(|h| unsafe { Remote::ref_from_raw(h) })
}
/// Get Remote by `address`
-pub fn get_remote_by_address<S: IntoCStr>(address: S) -> Option<Ref<Remote>> {
+pub fn get_remote_by_address(address: &str) -> Option<Ref<Remote>> {
let address = address.to_cstr();
let value = unsafe { BNCollaborationGetRemoteByAddress(address.as_ptr()) };
NonNull::new(value).map(|h| unsafe { Remote::ref_from_raw(h) })
}
/// Get Remote by `name`
-pub fn get_remote_by_name<S: IntoCStr>(name: S) -> Option<Ref<Remote>> {
+pub fn get_remote_by_name(name: &str) -> Option<Ref<Remote>> {
let name = name.to_cstr();
let value = unsafe { BNCollaborationGetRemoteByName(name.as_ptr()) };
NonNull::new(value).map(|h| unsafe { Remote::ref_from_raw(h) })
@@ -103,15 +103,12 @@ pub fn save_remotes() {
unsafe { BNCollaborationSaveRemotes() }
}
-pub fn store_data_in_keychain<K, I, DK, DV>(key: K, data: I) -> bool
+pub fn store_data_in_keychain<I>(key: &str, data: I) -> bool
where
- K: IntoCStr,
- I: IntoIterator<Item = (DK, DV)>,
- DK: IntoCStr,
- DV: IntoCStr,
+ I: IntoIterator<Item = (String, String)>,
{
let key = key.to_cstr();
- let (data_keys, data_values): (Vec<DK::Result>, Vec<DV::Result>) = data
+ let (data_keys, data_values): (Vec<_>, Vec<_>) = data
.into_iter()
.map(|(k, v)| (k.to_cstr(), v.to_cstr()))
.unzip();
@@ -127,12 +124,12 @@ where
}
}
-pub fn has_data_in_keychain<K: IntoCStr>(key: K) -> bool {
+pub fn has_data_in_keychain(key: &str) -> bool {
let key = key.to_cstr();
unsafe { BNCollaborationHasDataInKeychain(key.as_ptr()) }
}
-pub fn get_data_from_keychain<K: IntoCStr>(key: K) -> Option<(Array<BnString>, Array<BnString>)> {
+pub fn get_data_from_keychain(key: &str) -> Option<(Array<BnString>, Array<BnString>)> {
let key = key.to_cstr();
let mut keys = std::ptr::null_mut();
let mut values = std::ptr::null_mut();
@@ -142,7 +139,7 @@ pub fn get_data_from_keychain<K: IntoCStr>(key: K) -> Option<(Array<BnString>, A
keys.zip(values)
}
-pub fn delete_data_from_keychain<K: IntoCStr>(key: K) -> bool {
+pub fn delete_data_from_keychain(key: &str) -> bool {
let key = key.to_cstr();
unsafe { BNCollaborationDeleteDataFromKeychain(key.as_ptr()) }
}
diff --git a/rust/src/collaboration/changeset.rs b/rust/src/collaboration/changeset.rs
index b07f23de..cce750e6 100644
--- a/rust/src/collaboration/changeset.rs
+++ b/rust/src/collaboration/changeset.rs
@@ -65,7 +65,7 @@ impl Changeset {
}
/// Set the name of the changeset, e.g. in a name changeset function.
- pub fn set_name<S: IntoCStr>(&self, value: S) -> bool {
+ pub fn set_name(&self, value: &str) -> bool {
let value = value.to_cstr();
unsafe { BNCollaborationChangesetSetName(self.handle.as_ptr(), value.as_ptr()) }
}
diff --git a/rust/src/collaboration/file.rs b/rust/src/collaboration/file.rs
index 699b34b8..624a731a 100644
--- a/rust/src/collaboration/file.rs
+++ b/rust/src/collaboration/file.rs
@@ -1,5 +1,6 @@
use std::ffi::c_void;
use std::fmt::{Debug, Formatter};
+use std::path::Path;
use std::ptr::NonNull;
use std::time::SystemTime;
@@ -94,7 +95,7 @@ impl RemoteFile {
success.then_some(()).ok_or(())
}
- pub fn set_metadata<S: IntoCStr>(&self, folder: S) -> Result<(), ()> {
+ pub fn set_metadata(&self, folder: &str) -> Result<(), ()> {
let folder_raw = folder.to_cstr();
let success = unsafe { BNRemoteFileSetMetadata(self.handle.as_ptr(), folder_raw.as_ptr()) };
success.then_some(()).ok_or(())
@@ -185,7 +186,7 @@ impl RemoteFile {
}
/// Set the description of the file. You will need to push the file to update the remote version.
- pub fn set_name<S: IntoCStr>(&self, name: S) -> Result<(), ()> {
+ pub fn set_name(&self, name: &str) -> Result<(), ()> {
let name = name.to_cstr();
let success = unsafe { BNRemoteFileSetName(self.handle.as_ptr(), name.as_ptr()) };
success.then_some(()).ok_or(())
@@ -199,7 +200,7 @@ impl RemoteFile {
}
/// Set the description of the file. You will need to push the file to update the remote version.
- pub fn set_description<S: IntoCStr>(&self, description: S) -> Result<(), ()> {
+ pub fn set_description(&self, description: &str) -> Result<(), ()> {
let description = description.to_cstr();
let success =
unsafe { BNRemoteFileSetDescription(self.handle.as_ptr(), description.as_ptr()) };
@@ -249,7 +250,7 @@ impl RemoteFile {
/// Get a specific Snapshot in the File by its id
///
/// NOTE: If snapshots have not been pulled, they will be pulled upon calling this.
- pub fn snapshot_by_id<S: IntoCStr>(&self, id: S) -> Result<Option<Ref<RemoteSnapshot>>, ()> {
+ pub fn snapshot_by_id(&self, id: &str) -> Result<Option<Ref<RemoteSnapshot>>, ()> {
// TODO: This sync should be removed?
if !self.has_pulled_snapshots() {
self.pull_snapshots()?;
@@ -286,18 +287,16 @@ impl RemoteFile {
/// * `analysis_cache_contents` - Contents of analysis cache of snapshot
/// * `file` - New file contents (if contents changed)
/// * `parent_ids` - List of ids of parent snapshots (or empty if this is a root snapshot)
- pub fn create_snapshot<S, I>(
+ pub fn create_snapshot<I>(
&self,
- name: S,
+ name: &str,
contents: &mut [u8],
analysis_cache_contexts: &mut [u8],
file: &mut [u8],
parent_ids: I,
) -> Result<Ref<RemoteSnapshot>, ()>
where
- S: IntoCStr,
- I: IntoIterator,
- I::Item: IntoCStr,
+ I: IntoIterator<Item = String>,
{
self.create_snapshot_with_progress(
name,
@@ -317,9 +316,9 @@ impl RemoteFile {
/// * `file` - New file contents (if contents changed)
/// * `parent_ids` - List of ids of parent snapshots (or empty if this is a root snapshot)
/// * `progress` - Function to call on progress updates
- pub fn create_snapshot_with_progress<S, I, P>(
+ pub fn create_snapshot_with_progress<I, P>(
&self,
- name: S,
+ name: &str,
contents: &mut [u8],
analysis_cache_contexts: &mut [u8],
file: &mut [u8],
@@ -327,10 +326,8 @@ impl RemoteFile {
mut progress: P,
) -> Result<Ref<RemoteSnapshot>, ()>
where
- S: IntoCStr,
+ I: IntoIterator<Item = String>,
P: ProgressCallback,
- I: IntoIterator,
- I::Item: IntoCStr,
{
let name = name.to_cstr();
let parent_ids: Vec<_> = parent_ids.into_iter().map(|id| id.to_cstr()).collect();
@@ -403,10 +400,7 @@ impl RemoteFile {
///
/// * `db_path` - File path for saved database
/// * `progress_function` - Function to call for progress updates
- pub fn download<S>(&self, db_path: S) -> Result<Ref<FileMetadata>, ()>
- where
- S: IntoCStr,
- {
+ pub fn download(&self, db_path: &Path) -> Result<Ref<FileMetadata>, ()> {
sync::download_file(self, db_path)
}
@@ -416,20 +410,19 @@ impl RemoteFile {
///
/// * `db_path` - File path for saved database
/// * `progress_function` - Function to call for progress updates
- pub fn download_with_progress<S, F>(
+ pub fn download_with_progress<F>(
&self,
- db_path: S,
+ db_path: &Path,
progress_function: F,
) -> Result<Ref<FileMetadata>, ()>
where
- S: IntoCStr,
F: ProgressCallback,
{
sync::download_file_with_progress(self, db_path, progress_function)
}
/// Download a remote file and save it to a BNDB at the given `path`, returning the associated [`FileMetadata`].
- pub fn download_database<S: IntoCStr>(&self, path: S) -> Result<Ref<FileMetadata>, ()> {
+ pub fn download_database(&self, path: &Path) -> Result<Ref<FileMetadata>, ()> {
let file = self.download(path)?;
let database = file.database().ok_or(())?;
self.sync(&database, DatabaseConflictHandlerFail, NoNameChangeset)?;
@@ -437,11 +430,10 @@ impl RemoteFile {
}
// TODO: This might be a bad helper... maybe remove...
- // TODO: AsRef<Path>
/// Download a remote file and save it to a BNDB at the given `path`.
- pub fn download_database_with_progress<S: IntoCStr>(
+ pub fn download_database_with_progress(
&self,
- path: S,
+ path: &Path,
progress: impl ProgressCallback,
) -> Result<Ref<FileMetadata>, ()> {
let mut progress = progress.split(&[50, 50]);
diff --git a/rust/src/collaboration/folder.rs b/rust/src/collaboration/folder.rs
index 35ff0788..797bcdd4 100644
--- a/rust/src/collaboration/folder.rs
+++ b/rust/src/collaboration/folder.rs
@@ -103,7 +103,7 @@ impl RemoteFolder {
}
/// Set the display name of the folder. You will need to push the folder to update the remote version.
- pub fn set_name<S: IntoCStr>(&self, name: S) -> Result<(), ()> {
+ pub fn set_name(&self, name: &str) -> Result<(), ()> {
let name = name.to_cstr();
let success = unsafe { BNRemoteFolderSetName(self.handle.as_ptr(), name.as_ptr()) };
success.then_some(()).ok_or(())
@@ -117,7 +117,7 @@ impl RemoteFolder {
}
/// Set the description of the folder. You will need to push the folder to update the remote version.
- pub fn set_description<S: IntoCStr>(&self, description: S) -> Result<(), ()> {
+ pub fn set_description(&self, description: &str) -> Result<(), ()> {
let description = description.to_cstr();
let success =
unsafe { BNRemoteFolderSetDescription(self.handle.as_ptr(), description.as_ptr()) };
diff --git a/rust/src/collaboration/group.rs b/rust/src/collaboration/group.rs
index 08efa079..01f92169 100644
--- a/rust/src/collaboration/group.rs
+++ b/rust/src/collaboration/group.rs
@@ -49,7 +49,7 @@ impl RemoteGroup {
/// Set group name
/// You will need to push the group to update the Remote.
- pub fn set_name<U: IntoCStr>(&self, name: U) {
+ pub fn set_name(&self, name: &str) {
let name = name.to_cstr();
unsafe { BNCollaborationGroupSetName(self.handle.as_ptr(), name.as_ptr()) }
}
@@ -83,8 +83,7 @@ impl RemoteGroup {
/// You will need to push the group to update the Remote.
pub fn set_users<I>(&self, usernames: I) -> Result<(), ()>
where
- I: IntoIterator,
- I::Item: IntoCStr,
+ I: IntoIterator<Item = String>,
{
let usernames: Vec<_> = usernames.into_iter().map(|u| u.to_cstr()).collect();
let mut usernames_raw: Vec<_> = usernames.iter().map(|s| s.as_ptr()).collect();
@@ -102,7 +101,7 @@ impl RemoteGroup {
}
/// Test if a group has a user with the given username
- pub fn contains_user<U: IntoCStr>(&self, username: U) -> bool {
+ pub fn contains_user(&self, username: &str) -> bool {
let username = username.to_cstr();
unsafe { BNCollaborationGroupContainsUser(self.handle.as_ptr(), username.as_ptr()) }
}
diff --git a/rust/src/collaboration/merge.rs b/rust/src/collaboration/merge.rs
index 9ebf4cda..aea11701 100644
--- a/rust/src/collaboration/merge.rs
+++ b/rust/src/collaboration/merge.rs
@@ -48,7 +48,7 @@ impl MergeConflict {
NonNull::new(result).map(|handle| unsafe { Snapshot::from_raw(handle) })
}
- pub fn path_item_string<S: IntoCStr>(&self, path: S) -> Result<BnString, ()> {
+ pub fn path_item_string(&self, path: &str) -> Result<BnString, ()> {
let path = path.to_cstr();
let result = unsafe {
BNAnalysisMergeConflictGetPathItemString(self.handle.as_ptr(), path.as_ptr())
@@ -119,7 +119,7 @@ impl MergeConflict {
}
/// Call this when you've resolved the conflict to save the result
- pub fn success<S: IntoCStr>(&self, value: S) -> Result<(), ()> {
+ pub fn success(&self, value: &str) -> Result<(), ()> {
let value = value.to_cstr();
let success =
unsafe { BNAnalysisMergeConflictSuccess(self.handle.as_ptr(), value.as_ptr()) };
@@ -127,7 +127,7 @@ impl MergeConflict {
}
// TODO: Make a safe version of this that checks the path and if it holds a number
- pub unsafe fn get_path_item_number<S: IntoCStr>(&self, path_key: S) -> Option<u64> {
+ pub unsafe fn get_path_item_number(&self, path_key: &str) -> Option<u64> {
let path_key = path_key.to_cstr();
let value =
unsafe { BNAnalysisMergeConflictGetPathItem(self.handle.as_ptr(), path_key.as_ptr()) };
@@ -138,7 +138,7 @@ impl MergeConflict {
}
}
- pub unsafe fn get_path_item_string<S: IntoCStr>(&self, path_key: S) -> Option<BnString> {
+ pub unsafe fn get_path_item_string(&self, path_key: &str) -> Option<BnString> {
let path_key = path_key.to_cstr();
let value = unsafe {
BNAnalysisMergeConflictGetPathItemString(self.handle.as_ptr(), path_key.as_ptr())
diff --git a/rust/src/collaboration/project.rs b/rust/src/collaboration/project.rs
index 3d34da9e..fa46e477 100644
--- a/rust/src/collaboration/project.rs
+++ b/rust/src/collaboration/project.rs
@@ -1,4 +1,5 @@
use std::ffi::c_void;
+use std::path::PathBuf;
use std::ptr::NonNull;
use std::time::SystemTime;
@@ -136,7 +137,7 @@ impl RemoteProject {
}
/// Set the description of the file. You will need to push the file to update the remote version.
- pub fn set_name<S: IntoCStr>(&self, name: S) -> Result<(), ()> {
+ pub fn set_name(&self, name: &str) -> Result<(), ()> {
let name = name.to_cstr();
let success = unsafe { BNRemoteProjectSetName(self.handle.as_ptr(), name.as_ptr()) };
success.then_some(()).ok_or(())
@@ -150,7 +151,7 @@ impl RemoteProject {
}
/// Set the description of the file. You will need to push the file to update the remote version.
- pub fn set_description<S: IntoCStr>(&self, description: S) -> Result<(), ()> {
+ pub fn set_description(&self, description: &str) -> Result<(), ()> {
let description = description.to_cstr();
let success =
unsafe { BNRemoteProjectSetDescription(self.handle.as_ptr(), description.as_ptr()) };
@@ -169,7 +170,7 @@ impl RemoteProject {
/// Get the default directory path for a remote Project. This is based off the Setting for
/// collaboration.directory, the project's id, and the project's remote's id.
- pub fn default_path(&self) -> Result<BnString, ()> {
+ pub fn default_path(&self) -> Result<PathBuf, ()> {
sync::default_project_path(self)
}
@@ -221,7 +222,7 @@ impl RemoteProject {
///
/// NOTE: If the project has not been opened, it will be opened upon calling this.
/// NOTE: If files have not been pulled, they will be pulled upon calling this.
- pub fn get_file_by_id<S: IntoCStr>(&self, id: S) -> Result<Option<Ref<RemoteFile>>, ()> {
+ pub fn get_file_by_id(&self, id: &str) -> Result<Option<Ref<RemoteFile>>, ()> {
// TODO: This sync should be removed?
if !self.has_pulled_files() {
self.pull_files()?;
@@ -235,7 +236,7 @@ impl RemoteProject {
///
/// NOTE: If the project has not been opened, it will be opened upon calling this.
/// NOTE: If files have not been pulled, they will be pulled upon calling this.
- pub fn get_file_by_name<S: IntoCStr>(&self, name: S) -> Result<Option<Ref<RemoteFile>>, ()> {
+ pub fn get_file_by_name(&self, name: &str) -> Result<Option<Ref<RemoteFile>>, ()> {
// TODO: This sync should be removed?
if !self.has_pulled_files() {
self.pull_files()?;
@@ -282,20 +283,15 @@ impl RemoteProject {
/// * `description` - File description
/// * `parent_folder` - Folder that will contain the file
/// * `file_type` - Type of File to create
- pub fn create_file<F, N, D>(
+ pub fn create_file(
&self,
- filename: F,
+ filename: &str,
contents: &[u8],
- name: N,
- description: D,
+ name: &str,
+ description: &str,
parent_folder: Option<&RemoteFolder>,
file_type: RemoteFileType,
- ) -> Result<Ref<RemoteFile>, ()>
- where
- F: IntoCStr,
- N: IntoCStr,
- D: IntoCStr,
- {
+ ) -> Result<Ref<RemoteFile>, ()> {
self.create_file_with_progress(
filename,
contents,
@@ -318,20 +314,17 @@ impl RemoteProject {
/// * `parent_folder` - Folder that will contain the file
/// * `file_type` - Type of File to create
/// * `progress` - Function to call on upload progress updates
- pub fn create_file_with_progress<F, N, D, P>(
+ pub fn create_file_with_progress<P>(
&self,
- filename: F,
+ filename: &str,
contents: &[u8],
- name: N,
- description: D,
+ name: &str,
+ description: &str,
parent_folder: Option<&RemoteFolder>,
file_type: RemoteFileType,
mut progress: P,
) -> Result<Ref<RemoteFile>, ()>
where
- F: IntoCStr,
- N: IntoCStr,
- D: IntoCStr,
P: ProgressCallback,
{
// TODO: This sync should be removed?
@@ -364,11 +357,9 @@ impl RemoteProject {
/// Push an updated File object to the Remote
///
/// NOTE: If the project has not been opened, it will be opened upon calling this.
- pub fn push_file<I, K, V>(&self, file: &RemoteFile, extra_fields: I) -> Result<(), ()>
+ pub fn push_file<I>(&self, file: &RemoteFile, extra_fields: I) -> Result<(), ()>
where
- I: Iterator<Item = (K, V)>,
- K: IntoCStr,
- V: IntoCStr,
+ I: IntoIterator<Item = (String, String)>,
{
// TODO: This sync should be removed?
self.open()?;
@@ -421,7 +412,7 @@ impl RemoteProject {
///
/// NOTE: If the project has not been opened, it will be opened upon calling this.
/// NOTE: If folders have not been pulled, they will be pulled upon calling this.
- pub fn get_folder_by_id<S: IntoCStr>(&self, id: S) -> Result<Option<Ref<RemoteFolder>>, ()> {
+ pub fn get_folder_by_id(&self, id: &str) -> Result<Option<Ref<RemoteFolder>>, ()> {
// TODO: This sync should be removed?
if !self.has_pulled_folders() {
self.pull_folders()?;
@@ -465,16 +456,12 @@ impl RemoteProject {
/// * `name` - Displayed folder name
/// * `description` - Folder description
/// * `parent` - Parent folder (optional)
- pub fn create_folder<N, D>(
+ pub fn create_folder(
&self,
- name: N,
- description: D,
+ name: &str,
+ description: &str,
parent_folder: Option<&RemoteFolder>,
- ) -> Result<Ref<RemoteFolder>, ()>
- where
- N: IntoCStr,
- D: IntoCStr,
- {
+ ) -> Result<Ref<RemoteFolder>, ()> {
self.create_folder_with_progress(name, description, parent_folder, NoProgressCallback)
}
@@ -486,16 +473,14 @@ impl RemoteProject {
/// * `description` - Folder description
/// * `parent` - Parent folder (optional)
/// * `progress` - Function to call on upload progress updates
- pub fn create_folder_with_progress<N, D, P>(
+ pub fn create_folder_with_progress<P>(
&self,
- name: N,
- description: D,
+ name: &str,
+ description: &str,
parent_folder: Option<&RemoteFolder>,
mut progress: P,
) -> Result<Ref<RemoteFolder>, ()>
where
- N: IntoCStr,
- D: IntoCStr,
P: ProgressCallback,
{
// TODO: This sync should be removed?
@@ -526,11 +511,9 @@ impl RemoteProject {
///
/// * `folder` - Folder object which has been updated
/// * `extra_fields` - Extra HTTP fields to send with the update
- pub fn push_folder<I, K, V>(&self, folder: &RemoteFolder, extra_fields: I) -> Result<(), ()>
+ pub fn push_folder<I>(&self, folder: &RemoteFolder, extra_fields: I) -> Result<(), ()>
where
- I: Iterator<Item = (K, V)>,
- K: IntoCStr,
- V: IntoCStr,
+ I: IntoIterator<Item = (String, String)>,
{
// TODO: This sync should be removed?
self.open()?;
@@ -598,7 +581,7 @@ impl RemoteProject {
/// Get a specific permission in the Project by its id.
///
/// NOTE: If group or user permissions have not been pulled, they will be pulled upon calling this.
- pub fn get_permission_by_id<S: IntoCStr>(&self, id: S) -> Result<Option<Ref<Permission>>, ()> {
+ pub fn get_permission_by_id(&self, id: &str) -> Result<Option<Ref<Permission>>, ()> {
// TODO: This sync should be removed?
if !self.has_pulled_user_permissions() {
self.pull_user_permissions()?;
@@ -703,9 +686,9 @@ impl RemoteProject {
///
/// * `user_id` - User id
/// * `level` - Permission level
- pub fn create_user_permission<S: IntoCStr>(
+ pub fn create_user_permission(
&self,
- user_id: S,
+ user_id: &str,
level: CollaborationPermissionLevel,
) -> Result<Ref<Permission>, ()> {
self.create_user_permission_with_progress(user_id, level, NoProgressCallback)
@@ -718,9 +701,9 @@ impl RemoteProject {
/// * `user_id` - User id
/// * `level` - Permission level
/// * `progress` - The progress callback to call
- pub fn create_user_permission_with_progress<S: IntoCStr, F: ProgressCallback>(
+ pub fn create_user_permission_with_progress<F: ProgressCallback>(
&self,
- user_id: S,
+ user_id: &str,
level: CollaborationPermissionLevel,
mut progress: F,
) -> Result<Ref<Permission>, ()> {
@@ -746,15 +729,9 @@ impl RemoteProject {
///
/// * `permission` - Permission object which has been updated
/// * `extra_fields` - Extra HTTP fields to send with the update
- pub fn push_permission<I, K, V>(
- &self,
- permission: &Permission,
- extra_fields: I,
- ) -> Result<(), ()>
+ pub fn push_permission<I>(&self, permission: &Permission, extra_fields: I) -> Result<(), ()>
where
- I: Iterator<Item = (K, V)>,
- K: IntoCStr,
- V: IntoCStr,
+ I: IntoIterator<Item = (String, String)>,
{
let (keys, values): (Vec<_>, Vec<_>) = extra_fields
.into_iter()
@@ -788,7 +765,7 @@ impl RemoteProject {
/// # Arguments
///
/// * `username` - Username of user to check
- pub fn can_user_view<S: IntoCStr>(&self, username: S) -> bool {
+ pub fn can_user_view(&self, username: &str) -> bool {
let username = username.to_cstr();
unsafe { BNRemoteProjectCanUserView(self.handle.as_ptr(), username.as_ptr()) }
}
@@ -798,7 +775,7 @@ impl RemoteProject {
/// # Arguments
///
/// * `username` - Username of user to check
- pub fn can_user_edit<S: IntoCStr>(&self, username: S) -> bool {
+ pub fn can_user_edit(&self, username: &str) -> bool {
let username = username.to_cstr();
unsafe { BNRemoteProjectCanUserEdit(self.handle.as_ptr(), username.as_ptr()) }
}
@@ -808,7 +785,7 @@ impl RemoteProject {
/// # Arguments
///
/// * `username` - Username of user to check
- pub fn can_user_admin<S: IntoCStr>(&self, username: S) -> bool {
+ pub fn can_user_admin(&self, username: &str) -> bool {
let username = username.to_cstr();
unsafe { BNRemoteProjectCanUserAdmin(self.handle.as_ptr(), username.as_ptr()) }
}
diff --git a/rust/src/collaboration/remote.rs b/rust/src/collaboration/remote.rs
index baeba412..7b5828ef 100644
--- a/rust/src/collaboration/remote.rs
+++ b/rust/src/collaboration/remote.rs
@@ -27,7 +27,7 @@ impl Remote {
}
/// Create a Remote and add it to the list of known remotes (saved to Settings)
- pub fn new<N: IntoCStr, A: IntoCStr>(name: N, address: A) -> Ref<Self> {
+ pub fn new(name: &str, address: &str) -> Ref<Self> {
let name = name.to_cstr();
let address = address.to_cstr();
let result = unsafe { BNCollaborationCreateRemote(name.as_ptr(), address.as_ptr()) };
@@ -163,11 +163,7 @@ impl Remote {
}
/// Requests an authentication token using a username and password.
- pub fn request_authentication_token<U: IntoCStr, P: IntoCStr>(
- &self,
- username: U,
- password: P,
- ) -> Option<String> {
+ pub fn request_authentication_token(&self, username: &str, password: &str) -> Option<String> {
let username = username.to_cstr();
let password = password.to_cstr();
let token = unsafe {
@@ -219,7 +215,7 @@ impl Remote {
let password = options
.password
.expect("No password or token for connection!");
- let token = self.request_authentication_token(&options.username, password);
+ let token = self.request_authentication_token(&options.username, &password);
// TODO: Error if None.
token.unwrap().to_string()
}
@@ -275,7 +271,7 @@ impl Remote {
/// Gets a specific project in the Remote by its id.
///
/// NOTE: If projects have not been pulled, they will be pulled upon calling this.
- pub fn get_project_by_id<S: IntoCStr>(&self, id: S) -> Result<Option<Ref<RemoteProject>>, ()> {
+ pub fn get_project_by_id(&self, id: &str) -> Result<Option<Ref<RemoteProject>>, ()> {
if !self.has_pulled_projects() {
self.pull_projects()?;
}
@@ -288,10 +284,7 @@ impl Remote {
/// Gets a specific project in the Remote by its name.
///
/// NOTE: If projects have not been pulled, they will be pulled upon calling this.
- pub fn get_project_by_name<S: IntoCStr>(
- &self,
- name: S,
- ) -> Result<Option<Ref<RemoteProject>>, ()> {
+ pub fn get_project_by_name(&self, name: &str) -> Result<Option<Ref<RemoteProject>>, ()> {
if !self.has_pulled_projects() {
self.pull_projects()?;
}
@@ -331,11 +324,7 @@ impl Remote {
///
/// * `name` - Project name
/// * `description` - Project description
- pub fn create_project<N: IntoCStr, D: IntoCStr>(
- &self,
- name: N,
- description: D,
- ) -> Result<Ref<RemoteProject>, ()> {
+ pub fn create_project(&self, name: &str, description: &str) -> Result<Ref<RemoteProject>, ()> {
// TODO: Do we want this?
// TODO: If you have not yet pulled projects you will have never filled the map you will be placing your
// TODO: New project in.
@@ -380,11 +369,9 @@ impl Remote {
///
/// * `project` - Project object which has been updated
/// * `extra_fields` - Extra HTTP fields to send with the update
- pub fn push_project<I, K, V>(&self, project: &RemoteProject, extra_fields: I) -> Result<(), ()>
+ pub fn push_project<I>(&self, project: &RemoteProject, extra_fields: I) -> Result<(), ()>
where
- I: Iterator<Item = (K, V)>,
- K: IntoCStr,
- V: IntoCStr,
+ I: IntoIterator<Item = (String, String)>,
{
let (keys, values): (Vec<_>, Vec<_>) = extra_fields
.into_iter()
@@ -446,7 +433,7 @@ impl Remote {
///
/// If groups have not been pulled, they will be pulled upon calling this.
/// This function is only available to accounts with admin status on the Remote.
- pub fn get_group_by_name<S: IntoCStr>(&self, name: S) -> Result<Option<Ref<RemoteGroup>>, ()> {
+ pub fn get_group_by_name(&self, name: &str) -> Result<Option<Ref<RemoteGroup>>, ()> {
if !self.has_pulled_groups() {
self.pull_groups()?;
}
@@ -462,10 +449,7 @@ impl Remote {
/// # Arguments
///
/// * `prefix` - Prefix of name for groups
- pub fn search_groups<S: IntoCStr>(
- &self,
- prefix: S,
- ) -> Result<(Array<GroupId>, Array<BnString>), ()> {
+ pub fn search_groups(&self, prefix: &str) -> Result<(Array<GroupId>, Array<BnString>), ()> {
let prefix = prefix.to_cstr();
let mut count = 0;
let mut group_ids = std::ptr::null_mut();
@@ -524,11 +508,9 @@ impl Remote {
///
/// * `name` - Group name
/// * `usernames` - List of usernames of users in the group
- pub fn create_group<N, I>(&self, name: N, usernames: I) -> Result<Ref<RemoteGroup>, ()>
+ pub fn create_group<I>(&self, name: &str, usernames: I) -> Result<Ref<RemoteGroup>, ()>
where
- N: IntoCStr,
- I: IntoIterator,
- I::Item: IntoCStr,
+ I: IntoIterator<Item = String>,
{
let name = name.to_cstr();
let usernames: Vec<_> = usernames.into_iter().map(|s| s.to_cstr()).collect();
@@ -554,11 +536,9 @@ impl Remote {
///
/// * `group` - Group object which has been updated
/// * `extra_fields` - Extra HTTP fields to send with the update
- pub fn push_group<I, K, V>(&self, group: &RemoteGroup, extra_fields: I) -> Result<(), ()>
+ pub fn push_group<I>(&self, group: &RemoteGroup, extra_fields: I) -> Result<(), ()>
where
- I: IntoIterator<Item = (K, V)>,
- K: IntoCStr,
- V: IntoCStr,
+ I: IntoIterator<Item = (String, String)>,
{
let (keys, values): (Vec<_>, Vec<_>) = extra_fields
.into_iter()
@@ -617,7 +597,7 @@ impl Remote {
/// # Arguments
///
/// * `id` - The identifier of the user to retrieve.
- pub fn get_user_by_id<S: IntoCStr>(&self, id: S) -> Result<Option<Ref<RemoteUser>>, ()> {
+ pub fn get_user_by_id(&self, id: &str) -> Result<Option<Ref<RemoteUser>>, ()> {
if !self.has_pulled_users() {
self.pull_users()?;
}
@@ -635,10 +615,7 @@ impl Remote {
/// # Arguments
///
/// * `username` - The username of the user to retrieve.
- pub fn get_user_by_username<S: IntoCStr>(
- &self,
- username: S,
- ) -> Result<Option<Ref<RemoteUser>>, ()> {
+ pub fn get_user_by_username(&self, username: &str) -> Result<Option<Ref<RemoteUser>>, ()> {
if !self.has_pulled_users() {
self.pull_users()?;
}
@@ -665,10 +642,7 @@ impl Remote {
/// # Arguments
///
/// * `prefix` - The prefix to search for in usernames.
- pub fn search_users<S: IntoCStr>(
- &self,
- prefix: S,
- ) -> Result<(Array<BnString>, Array<BnString>), ()> {
+ pub fn search_users(&self, prefix: &str) -> Result<(Array<BnString>, Array<BnString>), ()> {
let prefix = prefix.to_cstr();
let mut count = 0;
let mut user_ids = std::ptr::null_mut();
@@ -730,12 +704,12 @@ impl Remote {
/// # Arguments
///
/// * Various details about the new user to be created.
- pub fn create_user<U: IntoCStr, E: IntoCStr, P: IntoCStr>(
+ pub fn create_user(
&self,
- username: U,
- email: E,
+ username: &str,
+ email: &str,
is_active: bool,
- password: P,
+ password: &str,
group_ids: &[u64],
user_permission_ids: &[u64],
) -> Result<Ref<RemoteUser>, ()> {
@@ -769,11 +743,9 @@ impl Remote {
///
/// * `user` - Reference to the `RemoteUser` object to push.
/// * `extra_fields` - Optional extra fields to send with the update.
- pub fn push_user<I, K, V>(&self, user: &RemoteUser, extra_fields: I) -> Result<(), ()>
+ pub fn push_user<I>(&self, user: &RemoteUser, extra_fields: I) -> Result<(), ()>
where
- I: Iterator<Item = (K, V)>,
- K: IntoCStr,
- V: IntoCStr,
+ I: IntoIterator<Item = (String, String)>,
{
let (keys, values): (Vec<_>, Vec<_>) = extra_fields
.into_iter()
diff --git a/rust/src/collaboration/snapshot.rs b/rust/src/collaboration/snapshot.rs
index c8256608..203d8677 100644
--- a/rust/src/collaboration/snapshot.rs
+++ b/rust/src/collaboration/snapshot.rs
@@ -226,10 +226,10 @@ impl RemoteSnapshot {
}
/// Create a new Undo Entry in this snapshot.
- pub fn create_undo_entry<S: IntoCStr>(
+ pub fn create_undo_entry(
&self,
parent: Option<u64>,
- data: S,
+ data: &str,
) -> Result<Ref<RemoteUndoEntry>, ()> {
let data = data.to_cstr();
let value = unsafe {
diff --git a/rust/src/collaboration/sync.rs b/rust/src/collaboration/sync.rs
index b1b26982..a8006b8b 100644
--- a/rust/src/collaboration/sync.rs
+++ b/rust/src/collaboration/sync.rs
@@ -3,6 +3,7 @@ use super::{
};
use binaryninjacore_sys::*;
use std::ffi::{c_char, c_void};
+use std::path::{Path, PathBuf};
use std::ptr::NonNull;
use crate::binary_view::{BinaryView, BinaryViewExt};
@@ -14,49 +15,45 @@ use crate::rc::Ref;
use crate::string::{raw_to_string, BnString, IntoCStr};
use crate::type_archive::{TypeArchive, TypeArchiveMergeConflict};
-// TODO: PathBuf
/// Get the default directory path for a remote Project. This is based off the Setting for
/// collaboration.directory, the project's id, and the project's remote's id.
-pub fn default_project_path(project: &RemoteProject) -> Result<BnString, ()> {
+pub fn default_project_path(project: &RemoteProject) -> Result<PathBuf, ()> {
let result = unsafe { BNCollaborationDefaultProjectPath(project.handle.as_ptr()) };
let success = !result.is_null();
success
- .then(|| unsafe { BnString::from_raw(result) })
+ .then(|| PathBuf::from(unsafe { BnString::into_string(result) }))
.ok_or(())
}
-// TODO: PathBuf
// Get the default filepath for a remote File. This is based off the Setting for
// collaboration.directory, the file's id, the file's project's id, and the file's
// remote's id.
-pub fn default_file_path(file: &RemoteFile) -> Result<BnString, ()> {
+pub fn default_file_path(file: &RemoteFile) -> Result<PathBuf, ()> {
let result = unsafe { BNCollaborationDefaultFilePath(file.handle.as_ptr()) };
let success = !result.is_null();
success
- .then(|| unsafe { BnString::from_raw(result) })
+ .then(|| PathBuf::from(unsafe { BnString::into_string(result) }))
.ok_or(())
}
-// TODO: AsRef<Path>
/// Download a file from its remote, saving all snapshots to a database in the
/// specified location. Returns a FileContext for opening the file later.
///
/// * `file` - Remote File to download and open
/// * `db_path` - File path for saved database
-pub fn download_file<S: IntoCStr>(file: &RemoteFile, db_path: S) -> Result<Ref<FileMetadata>, ()> {
+pub fn download_file(file: &RemoteFile, db_path: &Path) -> Result<Ref<FileMetadata>, ()> {
download_file_with_progress(file, db_path, NoProgressCallback)
}
-// TODO: AsRef<Path>
/// Download a file from its remote, saving all snapshots to a database in the
/// specified location. Returns a FileContext for opening the file later.
///
/// * `file` - Remote File to download and open
/// * `db_path` - File path for saved database
/// * `progress` - Function to call for progress updates
-pub fn download_file_with_progress<S: IntoCStr, F: ProgressCallback>(
+pub fn download_file_with_progress<F: ProgressCallback>(
file: &RemoteFile,
- db_path: S,
+ db_path: &Path,
mut progress: F,
) -> Result<Ref<FileMetadata>, ()> {
let db_path = db_path.to_cstr();
@@ -218,22 +215,18 @@ pub fn get_local_snapshot_for_remote(
.ok_or(())
}
-pub fn download_database<S>(file: &RemoteFile, location: S, force: bool) -> Result<(), ()>
-where
- S: IntoCStr,
-{
+pub fn download_database<S>(file: &RemoteFile, location: &Path, force: bool) -> Result<(), ()> {
download_database_with_progress(file, location, force, NoProgressCallback)
}
-pub fn download_database_with_progress<S, F>(
+pub fn download_database_with_progress<PC>(
file: &RemoteFile,
- location: S,
+ location: &Path,
force: bool,
- mut progress: F,
+ mut progress: PC,
) -> Result<(), ()>
where
- S: IntoCStr,
- F: ProgressCallback,
+ PC: ProgressCallback,
{
let db_path = location.to_cstr();
let success = unsafe {
@@ -241,8 +234,8 @@ where
file.handle.as_ptr(),
db_path.as_ptr(),
force,
- Some(F::cb_progress_callback),
- &mut progress as *mut _ as *mut c_void,
+ Some(PC::cb_progress_callback),
+ &mut progress as *mut PC as *mut c_void,
)
};
success.then_some(()).ok_or(())
@@ -475,10 +468,10 @@ pub fn get_snapshot_author(
/// * `database` - Parent database
/// * `snapshot` - Snapshot to edit
/// * `author` - Target author
-pub fn set_snapshot_author<S: IntoCStr>(
+pub fn set_snapshot_author(
database: &Database,
snapshot: &Snapshot,
- author: S,
+ author: &str,
) -> Result<(), ()> {
let author = author.to_cstr();
let success = unsafe {
@@ -650,9 +643,9 @@ pub fn get_remote_file_for_local_type_archive(database: &TypeArchive) -> Option<
}
/// Get the remote snapshot associated with a local snapshot (if it exists) in a Type Archive
-pub fn get_remote_snapshot_from_local_type_archive<S: IntoCStr>(
+pub fn get_remote_snapshot_from_local_type_archive(
type_archive: &TypeArchive,
- snapshot_id: S,
+ snapshot_id: &str,
) -> Option<Ref<RemoteSnapshot>> {
let snapshot_id = snapshot_id.to_cstr();
let value = unsafe {
@@ -679,10 +672,7 @@ pub fn get_local_snapshot_from_remote_type_archive(
}
/// Test if a snapshot is ignored from the archive
-pub fn is_type_archive_snapshot_ignored<S: IntoCStr>(
- type_archive: &TypeArchive,
- snapshot_id: S,
-) -> bool {
+pub fn is_type_archive_snapshot_ignored(type_archive: &TypeArchive, snapshot_id: &str) -> bool {
let snapshot_id = snapshot_id.to_cstr();
unsafe {
BNCollaborationIsTypeArchiveSnapshotIgnored(
@@ -694,19 +684,19 @@ pub fn is_type_archive_snapshot_ignored<S: IntoCStr>(
/// Download a type archive from its remote, saving all snapshots to an archive in the
/// specified `location`. Returns a [`TypeArchive`] for using later.
-pub fn download_type_archive<S: IntoCStr>(
+pub fn download_type_archive(
file: &RemoteFile,
- location: S,
+ location: &Path,
) -> Result<Option<Ref<TypeArchive>>, ()> {
download_type_archive_with_progress(file, location, NoProgressCallback)
}
/// Download a type archive from its remote, saving all snapshots to an archive in the
/// specified `location`. Returns a [`TypeArchive`] for using later.
-pub fn download_type_archive_with_progress<S: IntoCStr, F: ProgressCallback>(
+pub fn download_type_archive_with_progress<PC: ProgressCallback>(
file: &RemoteFile,
- location: S,
- mut progress: F,
+ location: &Path,
+ mut progress: PC,
) -> Result<Option<Ref<TypeArchive>>, ()> {
let mut value = std::ptr::null_mut();
let db_path = location.to_cstr();
@@ -714,8 +704,8 @@ pub fn download_type_archive_with_progress<S: IntoCStr, F: ProgressCallback>(
BNCollaborationDownloadTypeArchive(
file.handle.as_ptr(),
db_path.as_ptr(),
- Some(F::cb_progress_callback),
- &mut progress as *mut F as *mut c_void,
+ Some(PC::cb_progress_callback),
+ &mut progress as *mut PC as *mut c_void,
&mut value,
)
};
diff --git a/rust/src/collaboration/user.rs b/rust/src/collaboration/user.rs
index 6b490942..51bdebb5 100644
--- a/rust/src/collaboration/user.rs
+++ b/rust/src/collaboration/user.rs
@@ -48,7 +48,7 @@ impl RemoteUser {
}
/// Set user's username. You will need to push the user to update the Remote
- pub fn set_username<U: IntoCStr>(&self, username: U) -> Result<(), ()> {
+ pub fn set_username(&self, username: &str) -> Result<(), ()> {
let username = username.to_cstr();
let result =
unsafe { BNCollaborationUserSetUsername(self.handle.as_ptr(), username.as_ptr()) };
@@ -67,7 +67,7 @@ impl RemoteUser {
}
/// Set user's email. You will need to push the user to update the Remote
- pub fn set_email<U: IntoCStr>(&self, email: U) -> Result<(), ()> {
+ pub fn set_email(&self, email: &str) -> Result<(), ()> {
let username = email.to_cstr();
let result =
unsafe { BNCollaborationUserSetEmail(self.handle.as_ptr(), username.as_ptr()) };
diff --git a/rust/src/command.rs b/rust/src/command.rs
index 099eafa8..46f43bbd 100644
--- a/rust/src/command.rs
+++ b/rust/src/command.rs
@@ -93,11 +93,7 @@ where
/// true
/// }
/// ```
-pub fn register_command<S, C>(name: S, desc: S, command: C)
-where
- S: IntoCStr,
- C: Command,
-{
+pub fn register_command<C: Command>(name: &str, desc: &str, command: C) {
extern "C" fn cb_action<C>(ctxt: *mut c_void, view: *mut BNBinaryView)
where
C: Command,
@@ -194,11 +190,7 @@ where
/// true
/// }
/// ```
-pub fn register_command_for_address<S, C>(name: S, desc: S, command: C)
-where
- S: IntoCStr,
- C: AddressCommand,
-{
+pub fn register_command_for_address<C: AddressCommand>(name: &str, desc: &str, command: C) {
extern "C" fn cb_action<C>(ctxt: *mut c_void, view: *mut BNBinaryView, addr: u64)
where
C: AddressCommand,
@@ -296,9 +288,8 @@ where
/// true
/// }
/// ```
-pub fn register_command_for_range<S, C>(name: S, desc: S, command: C)
+pub fn register_command_for_range<C>(name: &str, desc: &str, command: C)
where
- S: IntoCStr,
C: RangeCommand,
{
extern "C" fn cb_action<C>(ctxt: *mut c_void, view: *mut BNBinaryView, addr: u64, len: u64)
@@ -403,11 +394,7 @@ where
/// true
/// }
/// ```
-pub fn register_command_for_function<S, C>(name: S, desc: S, command: C)
-where
- S: IntoCStr,
- C: FunctionCommand,
-{
+pub fn register_command_for_function<C: FunctionCommand>(name: &str, desc: &str, command: C) {
extern "C" fn cb_action<C>(ctxt: *mut c_void, view: *mut BNBinaryView, func: *mut BNFunction)
where
C: FunctionCommand,
diff --git a/rust/src/component.rs b/rust/src/component.rs
index ae5fd55e..4c5d5992 100644
--- a/rust/src/component.rs
+++ b/rust/src/component.rs
@@ -164,7 +164,7 @@ impl Component {
unsafe { BnString::into_string(result) }
}
- pub fn set_name<S: IntoCStr>(&self, name: S) {
+ pub fn set_name(&self, name: &str) {
let name = name.to_cstr();
unsafe { BNComponentSetName(self.handle.as_ptr(), name.as_ptr()) }
}
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() {
diff --git a/rust/src/data_buffer.rs b/rust/src/data_buffer.rs
index bfffc33f..a3f51d54 100644
--- a/rust/src/data_buffer.rs
+++ b/rust/src/data_buffer.rs
@@ -120,7 +120,8 @@ impl DataBuffer {
}
}
- pub fn from_escaped_string(value: &BnString) -> Self {
+ pub fn from_escaped_string(value: &str) -> Self {
+ let value = value.to_cstr();
Self(unsafe { BNDecodeEscapedString(value.as_ptr()) })
}
diff --git a/rust/src/database.rs b/rust/src/database.rs
index 1746b405..4f2b3f6a 100644
--- a/rust/src/database.rs
+++ b/rust/src/database.rs
@@ -62,11 +62,11 @@ impl Database {
unsafe { BNSetDatabaseCurrentSnapshot(self.handle.as_ptr(), id.0) }
}
- pub fn write_snapshot_data<N: IntoCStr>(
+ pub fn write_snapshot_data(
&self,
parents: &[SnapshotId],
file: &BinaryView,
- name: N,
+ name: &str,
data: &KeyValueStore,
auto_save: bool,
) -> SnapshotId {
@@ -80,17 +80,16 @@ impl Database {
)
}
- pub fn write_snapshot_data_with_progress<N, P>(
+ pub fn write_snapshot_data_with_progress<P>(
&self,
parents: &[SnapshotId],
file: &BinaryView,
- name: N,
+ name: &str,
data: &KeyValueStore,
auto_save: bool,
mut progress: P,
) -> SnapshotId
where
- N: IntoCStr,
P: ProgressCallback,
{
let name_raw = name.to_cstr();
@@ -133,7 +132,7 @@ impl Database {
Err(())
}
}
- pub fn has_global<S: IntoCStr>(&self, key: S) -> bool {
+ pub fn has_global(&self, key: &str) -> bool {
let key_raw = key.to_cstr();
unsafe { BNDatabaseHasGlobal(self.handle.as_ptr(), key_raw.as_ptr()) != 0 }
}
@@ -155,28 +154,28 @@ impl Database {
}
/// Get a specific global by key
- pub fn read_global<S: IntoCStr>(&self, key: S) -> Option<BnString> {
+ pub fn read_global(&self, key: &str) -> Option<BnString> {
let key_raw = key.to_cstr();
let result = unsafe { BNReadDatabaseGlobal(self.handle.as_ptr(), key_raw.as_ptr()) };
unsafe { NonNull::new(result).map(|_| BnString::from_raw(result)) }
}
/// Write a global into the database
- pub fn write_global<K: IntoCStr, V: IntoCStr>(&self, key: K, value: V) -> bool {
+ pub fn write_global(&self, key: &str, value: &str) -> bool {
let key_raw = key.to_cstr();
let value_raw = value.to_cstr();
unsafe { BNWriteDatabaseGlobal(self.handle.as_ptr(), key_raw.as_ptr(), value_raw.as_ptr()) }
}
/// Get a specific global by key, as a binary buffer
- pub fn read_global_data<S: IntoCStr>(&self, key: S) -> Option<DataBuffer> {
+ pub fn read_global_data(&self, key: &str) -> Option<DataBuffer> {
let key_raw = key.to_cstr();
let result = unsafe { BNReadDatabaseGlobalData(self.handle.as_ptr(), key_raw.as_ptr()) };
NonNull::new(result).map(|_| DataBuffer::from_raw(result))
}
/// Write a binary buffer into a global in the database
- pub fn write_global_data<K: IntoCStr>(&self, key: K, value: &DataBuffer) -> bool {
+ pub fn write_global_data(&self, key: &str, value: &DataBuffer) -> bool {
let key_raw = key.to_cstr();
unsafe { BNWriteDatabaseGlobalData(self.handle.as_ptr(), key_raw.as_ptr(), value.as_raw()) }
}
diff --git a/rust/src/database/kvs.rs b/rust/src/database/kvs.rs
index 5b7cbbe8..13b17962 100644
--- a/rust/src/database/kvs.rs
+++ b/rust/src/database/kvs.rs
@@ -41,7 +41,7 @@ impl KeyValueStore {
}
/// Get the value for a single key
- pub fn value<S: IntoCStr>(&self, key: S) -> Option<DataBuffer> {
+ pub fn value(&self, key: &str) -> Option<DataBuffer> {
let key_raw = key.to_cstr();
let key_ptr = key_raw.as_ptr();
let result = unsafe { BNGetKeyValueStoreBuffer(self.handle.as_ptr(), key_ptr) };
@@ -49,7 +49,7 @@ impl KeyValueStore {
}
/// Set the value for a single key
- pub fn set_value<S: IntoCStr>(&self, key: S, value: &DataBuffer) -> bool {
+ pub fn set_value(&self, key: &str, value: &DataBuffer) -> bool {
let key_raw = key.to_cstr();
let key_ptr = key_raw.as_ptr();
unsafe { BNSetKeyValueStoreBuffer(self.handle.as_ptr(), key_ptr, value.as_raw()) }
@@ -63,7 +63,7 @@ impl KeyValueStore {
}
/// Begin storing new keys into a namespace
- pub fn begin_namespace<S: IntoCStr>(&self, name: S) {
+ pub fn begin_namespace(&self, name: &str) {
let name_raw = name.to_cstr();
let name_ptr = name_raw.as_ptr();
unsafe { BNBeginKeyValueStoreNamespace(self.handle.as_ptr(), name_ptr) }
diff --git a/rust/src/database/snapshot.rs b/rust/src/database/snapshot.rs
index d9ff030a..85c57f4e 100644
--- a/rust/src/database/snapshot.rs
+++ b/rust/src/database/snapshot.rs
@@ -50,7 +50,7 @@ impl Snapshot {
}
/// Set the displayed snapshot name
- pub fn set_name<S: IntoCStr>(&self, value: S) {
+ pub fn set_name(&self, value: &str) {
let value_raw = value.to_cstr();
let value_ptr = value_raw.as_ptr();
unsafe { BNSetSnapshotName(self.handle.as_ptr(), value_ptr) }
diff --git a/rust/src/debuginfo.rs b/rust/src/debuginfo.rs
index 248726f3..a4d0b139 100644
--- a/rust/src/debuginfo.rs
+++ b/rust/src/debuginfo.rs
@@ -115,7 +115,7 @@ impl DebugInfoParser {
}
/// Returns debug info parser of the given name, if it exists
- pub fn from_name<S: IntoCStr>(name: S) -> Result<Ref<Self>, ()> {
+ pub fn from_name(name: &str) -> Result<Ref<Self>, ()> {
let name = name.to_cstr();
let parser = unsafe { BNGetDebugInfoParserByName(name.as_ptr()) };
@@ -207,9 +207,8 @@ impl DebugInfoParser {
}
// Registers a DebugInfoParser. See `binaryninja::debuginfo::DebugInfoParser` for more details.
- pub fn register<S, C>(name: S, parser_callbacks: C) -> Ref<Self>
+ pub fn register<C>(name: &str, parser_callbacks: C) -> Ref<Self>
where
- S: IntoCStr,
C: CustomDebugInfoParser,
{
extern "C" fn cb_is_valid<C>(ctxt: *mut c_void, view: *mut BNBinaryView) -> bool
@@ -418,7 +417,7 @@ impl DebugInfo {
}
/// Returns all types within the parser
- pub fn types_by_name<S: IntoCStr>(&self, parser_name: S) -> Vec<NameAndType> {
+ pub fn types_by_name(&self, parser_name: &str) -> Vec<NameAndType> {
let parser_name = parser_name.to_cstr();
let mut count: usize = 0;
@@ -451,7 +450,7 @@ impl DebugInfo {
}
/// Returns all functions within the parser
- pub fn functions_by_name<S: IntoCStr>(&self, parser_name: S) -> Vec<DebugFunctionInfo> {
+ pub fn functions_by_name(&self, parser_name: &str) -> Vec<DebugFunctionInfo> {
let parser_name = parser_name.to_cstr();
let mut count: usize = 0;
@@ -486,10 +485,7 @@ impl DebugInfo {
}
/// Returns all data variables within the parser
- pub fn data_variables_by_name<S: IntoCStr>(
- &self,
- parser_name: S,
- ) -> Vec<NamedDataVariableWithType> {
+ pub fn data_variables_by_name(&self, parser_name: &str) -> Vec<NamedDataVariableWithType> {
let parser_name = parser_name.to_cstr();
let mut count: usize = 0;
@@ -523,7 +519,7 @@ impl DebugInfo {
result
}
- pub fn type_by_name<S: IntoCStr>(&self, parser_name: S, name: S) -> Option<Ref<Type>> {
+ pub fn type_by_name(&self, parser_name: &str, name: &str) -> Option<Ref<Type>> {
let parser_name = parser_name.to_cstr();
let name = name.to_cstr();
@@ -536,10 +532,10 @@ impl DebugInfo {
}
}
- pub fn get_data_variable_by_name<S: IntoCStr>(
+ pub fn get_data_variable_by_name(
&self,
- parser_name: S,
- name: S,
+ parser_name: &str,
+ name: &str,
) -> Option<NamedDataVariableWithType> {
let parser_name = parser_name.to_cstr();
let name = name.to_cstr();
@@ -558,9 +554,9 @@ impl DebugInfo {
}
}
- pub fn get_data_variable_by_address<S: IntoCStr>(
+ pub fn get_data_variable_by_address(
&self,
- parser_name: S,
+ parser_name: &str,
address: u64,
) -> Option<NamedDataVariableWithType> {
let parser_name = parser_name.to_cstr();
@@ -576,7 +572,7 @@ impl DebugInfo {
}
/// Returns a list of [`NameAndType`] where the `name` is the parser the type originates from.
- pub fn get_types_by_name<S: IntoCStr>(&self, name: S) -> Vec<NameAndType> {
+ pub fn get_types_by_name(&self, name: &str) -> Vec<NameAndType> {
let mut count: usize = 0;
let name = name.to_cstr();
let raw_names_and_types_ptr =
@@ -595,10 +591,7 @@ impl DebugInfo {
}
// The tuple is (DebugInfoParserName, address, type)
- pub fn get_data_variables_by_name<S: IntoCStr>(
- &self,
- name: S,
- ) -> Vec<(String, u64, Ref<Type>)> {
+ pub fn get_data_variables_by_name(&self, name: &str) -> Vec<(String, u64, Ref<Type>)> {
let name = name.to_cstr();
let mut count: usize = 0;
@@ -649,55 +642,51 @@ impl DebugInfo {
result
}
- pub fn remove_parser_info<S: IntoCStr>(&self, parser_name: S) -> bool {
+ pub fn remove_parser_info(&self, parser_name: &str) -> bool {
let parser_name = parser_name.to_cstr();
unsafe { BNRemoveDebugParserInfo(self.handle, parser_name.as_ptr()) }
}
- pub fn remove_parser_types<S: IntoCStr>(&self, parser_name: S) -> bool {
+ pub fn remove_parser_types(&self, parser_name: &str) -> bool {
let parser_name = parser_name.to_cstr();
unsafe { BNRemoveDebugParserTypes(self.handle, parser_name.as_ptr()) }
}
- pub fn remove_parser_functions<S: IntoCStr>(&self, parser_name: S) -> bool {
+ pub fn remove_parser_functions(&self, parser_name: &str) -> bool {
let parser_name = parser_name.to_cstr();
unsafe { BNRemoveDebugParserFunctions(self.handle, parser_name.as_ptr()) }
}
- pub fn remove_parser_data_variables<S: IntoCStr>(&self, parser_name: S) -> bool {
+ pub fn remove_parser_data_variables(&self, parser_name: &str) -> bool {
let parser_name = parser_name.to_cstr();
unsafe { BNRemoveDebugParserDataVariables(self.handle, parser_name.as_ptr()) }
}
- pub fn remove_type_by_name<S: IntoCStr>(&self, parser_name: S, name: S) -> bool {
+ pub fn remove_type_by_name(&self, parser_name: &str, name: &str) -> bool {
let parser_name = parser_name.to_cstr();
let name = name.to_cstr();
unsafe { BNRemoveDebugTypeByName(self.handle, parser_name.as_ptr(), name.as_ptr()) }
}
- pub fn remove_function_by_index<S: IntoCStr>(&self, parser_name: S, index: usize) -> bool {
+ pub fn remove_function_by_index(&self, parser_name: &str, index: usize) -> bool {
let parser_name = parser_name.to_cstr();
unsafe { BNRemoveDebugFunctionByIndex(self.handle, parser_name.as_ptr(), index) }
}
- pub fn remove_data_variable_by_address<S: IntoCStr>(
- &self,
- parser_name: S,
- address: u64,
- ) -> bool {
+ pub fn remove_data_variable_by_address(&self, parser_name: &str, address: u64) -> bool {
let parser_name = parser_name.to_cstr();
unsafe { BNRemoveDebugDataVariableByAddress(self.handle, parser_name.as_ptr(), address) }
}
/// Adds a type scoped under the current parser's name to the debug info
- pub fn add_type<S: IntoCStr>(&self, name: S, new_type: &Type, components: &[&str]) -> bool {
+ pub fn add_type(&self, name: &str, new_type: &Type, components: &[&str]) -> bool {
// SAFETY: Lifetime of `components` will live long enough, so passing as_ptr is safe.
let raw_components: Vec<_> = components.iter().map(|&c| c.as_ptr()).collect();
@@ -779,11 +768,11 @@ impl DebugInfo {
}
/// Adds a data variable scoped under the current parser's name to the debug info
- pub fn add_data_variable<S: IntoCStr>(
+ pub fn add_data_variable(
&self,
address: u64,
t: &Type,
- name: Option<S>,
+ name: Option<&str>,
components: &[&str],
) -> bool {
let mut components_array: Vec<*const ::std::os::raw::c_char> =
diff --git a/rust/src/demangle.rs b/rust/src/demangle.rs
index 68b349ca..50878bda 100644
--- a/rust/src/demangle.rs
+++ b/rust/src/demangle.rs
@@ -26,9 +26,9 @@ use crate::rc::*;
pub type Result<R> = std::result::Result<R, ()>;
-pub fn demangle_generic<S: IntoCStr>(
+pub fn demangle_generic(
arch: &CoreArchitecture,
- mangled_name: S,
+ mangled_name: &str,
view: Option<&BinaryView>,
simplify: bool,
) -> Option<(QualifiedName, Option<Ref<Type>>)> {
@@ -57,7 +57,7 @@ pub fn demangle_generic<S: IntoCStr>(
}
}
-pub fn demangle_llvm<S: IntoCStr>(mangled_name: S, simplify: bool) -> Option<QualifiedName> {
+pub fn demangle_llvm(mangled_name: &str, simplify: bool) -> Option<QualifiedName> {
let mangled_name = mangled_name.to_cstr();
let mut out_name: *mut *mut std::os::raw::c_char = std::ptr::null_mut();
let mut out_size: usize = 0;
@@ -85,9 +85,9 @@ pub fn demangle_llvm<S: IntoCStr>(mangled_name: S, simplify: bool) -> Option<Qua
}
}
-pub fn demangle_gnu3<S: IntoCStr>(
+pub fn demangle_gnu3(
arch: &CoreArchitecture,
- mangled_name: S,
+ mangled_name: &str,
simplify: bool,
) -> Option<(QualifiedName, Option<Ref<Type>>)> {
let mangled_name = mangled_name.to_cstr();
@@ -125,9 +125,9 @@ pub fn demangle_gnu3<S: IntoCStr>(
}
}
-pub fn demangle_ms<S: IntoCStr>(
+pub fn demangle_ms(
arch: &CoreArchitecture,
- mangled_name: S,
+ mangled_name: &str,
simplify: bool,
) -> Option<(QualifiedName, Option<Ref<Type>>)> {
let mangled_name = mangled_name.to_cstr();
@@ -182,15 +182,15 @@ impl Demangler {
unsafe { Array::<Demangler>::new(demanglers, count, ()) }
}
- pub fn is_mangled_string<S: IntoCStr>(&self, name: S) -> bool {
+ pub fn is_mangled_string(&self, name: &str) -> bool {
let bytes = name.to_cstr();
unsafe { BNIsDemanglerMangledName(self.handle, bytes.as_ref().as_ptr() as *const _) }
}
- pub fn demangle<S: IntoCStr>(
+ pub fn demangle(
&self,
arch: &CoreArchitecture,
- name: S,
+ name: &str,
view: Option<&BinaryView>,
) -> Option<(QualifiedName, Option<Ref<Type>>)> {
let name_bytes = name.to_cstr();
@@ -231,7 +231,7 @@ impl Demangler {
unsafe { BnString::into_string(BNGetDemanglerName(self.handle)) }
}
- pub fn from_name<S: IntoCStr>(name: S) -> Option<Self> {
+ pub fn from_name(name: &str) -> Option<Self> {
let name_bytes = name.to_cstr();
let demangler = unsafe { BNGetDemanglerByName(name_bytes.as_ref().as_ptr() as *const _) };
if demangler.is_null() {
@@ -241,11 +241,7 @@ impl Demangler {
}
}
- pub fn register<S, C>(name: S, demangler: C) -> Self
- where
- S: IntoCStr,
- C: CustomDemangler,
- {
+ pub fn register<C: CustomDemangler>(name: &str, demangler: C) -> Self {
extern "C" fn cb_is_mangled_string<C>(ctxt: *mut c_void, name: *const c_char) -> bool
where
C: CustomDemangler,
diff --git a/rust/src/disassembly.rs b/rust/src/disassembly.rs
index 396bcfcc..973fd57c 100644
--- a/rust/src/disassembly.rs
+++ b/rust/src/disassembly.rs
@@ -1242,13 +1242,13 @@ impl DisassemblyTextRenderer {
unsafe { Array::new(tokens, count, ()) }
}
- pub fn wrap_comment<S1: IntoCStr, S2: IntoCStr, S3: IntoCStr>(
+ pub fn wrap_comment(
&self,
cur_line: DisassemblyTextLine,
- comment: S1,
+ comment: &str,
has_auto_annotations: bool,
- leading_spaces: S2,
- indent_spaces: S3,
+ leading_spaces: &str,
+ indent_spaces: &str,
) -> Array<DisassemblyTextLine> {
let cur_line_raw = DisassemblyTextLine::into_raw(cur_line);
let comment_raw = comment.to_cstr();
diff --git a/rust/src/download_provider.rs b/rust/src/download_provider.rs
index e74274f4..9fd803a7 100644
--- a/rust/src/download_provider.rs
+++ b/rust/src/download_provider.rs
@@ -13,7 +13,7 @@ pub struct DownloadProvider {
}
impl DownloadProvider {
- pub fn get<S: IntoCStr>(name: S) -> Option<DownloadProvider> {
+ pub fn get(name: &str) -> Option<DownloadProvider> {
let name = name.to_cstr();
let result = unsafe { BNGetDownloadProviderByName(name.as_ptr()) };
if result.is_null() {
@@ -37,7 +37,7 @@ impl DownloadProvider {
pub fn try_default() -> Result<DownloadProvider, ()> {
let s = Settings::new();
let dp_name = s.get_string("network.downloadProviderName");
- Self::get(dp_name).ok_or(())
+ Self::get(&dp_name).ok_or(())
}
pub(crate) fn from_raw(handle: *mut BNDownloadProvider) -> DownloadProvider {
@@ -131,9 +131,9 @@ impl DownloadInstance {
}
}
- pub fn perform_request<S: IntoCStr>(
+ pub fn perform_request(
&mut self,
- url: S,
+ url: &str,
callbacks: DownloadInstanceOutputCallbacks,
) -> Result<(), String> {
let callbacks = Box::into_raw(Box::new(callbacks));
@@ -201,19 +201,16 @@ impl DownloadInstance {
}
}
- pub fn perform_custom_request<
- M: IntoCStr,
- U: IntoCStr,
- HK: IntoCStr,
- HV: IntoCStr,
- I: Iterator<Item = (HK, HV)>,
- >(
+ pub fn perform_custom_request<I>(
&mut self,
- method: M,
- url: U,
+ method: &str,
+ url: &str,
headers: I,
callbacks: DownloadInstanceInputOutputCallbacks,
- ) -> Result<DownloadResponse, String> {
+ ) -> Result<DownloadResponse, String>
+ where
+ I: IntoIterator<Item = (String, String)>,
+ {
let mut header_keys = vec![];
let mut header_values = vec![];
for (key, value) in headers {
diff --git a/rust/src/enterprise.rs b/rust/src/enterprise.rs
index 7c2aad19..68ad069c 100644
--- a/rust/src/enterprise.rs
+++ b/rust/src/enterprise.rs
@@ -66,7 +66,7 @@ pub fn checkout_license(
.map_err(|_| EnterpriseCheckoutError::NoUsername)?;
let password = std::env::var("BN_ENTERPRISE_PASSWORD")
.map_err(|_| EnterpriseCheckoutError::NoPassword)?;
- if !authenticate_server_with_credentials(username, password, true) {
+ if !authenticate_server_with_credentials(&username, &password, true) {
return Err(EnterpriseCheckoutError::NotAuthenticated);
}
}
@@ -120,7 +120,7 @@ pub fn server_url() -> String {
unsafe { BnString::into_string(binaryninjacore_sys::BNGetEnterpriseServerUrl()) }
}
-pub fn set_server_url<S: IntoCStr>(url: S) -> Result<(), ()> {
+pub fn set_server_url(url: &str) -> Result<(), ()> {
let url = url.to_cstr();
let result = unsafe {
binaryninjacore_sys::BNSetEnterpriseServerUrl(
@@ -183,11 +183,11 @@ pub fn is_server_license_still_activated() -> bool {
unsafe { binaryninjacore_sys::BNIsEnterpriseServerLicenseStillActivated() }
}
-pub fn authenticate_server_with_credentials<U, P>(username: U, password: P, remember: bool) -> bool
-where
- U: IntoCStr,
- P: IntoCStr,
-{
+pub fn authenticate_server_with_credentials(
+ username: &str,
+ password: &str,
+ remember: bool,
+) -> bool {
let username = username.to_cstr();
let password = password.to_cstr();
unsafe {
@@ -199,7 +199,7 @@ where
}
}
-pub fn authenticate_server_with_method<S: IntoCStr>(method: S, remember: bool) -> bool {
+pub fn authenticate_server_with_method(method: &str, remember: bool) -> bool {
let method = method.to_cstr();
unsafe {
binaryninjacore_sys::BNAuthenticateEnterpriseServerWithMethod(
diff --git a/rust/src/external_library.rs b/rust/src/external_library.rs
index 4f6e0e84..148fd030 100644
--- a/rust/src/external_library.rs
+++ b/rust/src/external_library.rs
@@ -166,7 +166,7 @@ impl ExternalLocation {
/// Set the symbol pointed to by this ExternalLocation.
/// ExternalLocations must have a valid target address and/or symbol set.
- pub fn set_target_symbol<S: IntoCStr>(&self, symbol: Option<S>) -> bool {
+ pub fn set_target_symbol(&self, symbol: Option<&str>) -> bool {
match symbol {
Some(sym) => {
let raw_sym = sym.to_cstr();
diff --git a/rust/src/file_metadata.rs b/rust/src/file_metadata.rs
index deec36f0..d4de13a2 100644
--- a/rust/src/file_metadata.rs
+++ b/rust/src/file_metadata.rs
@@ -52,7 +52,7 @@ impl FileMetadata {
Self::ref_from_raw(unsafe { BNCreateFileMetadata() })
}
- pub fn with_filename<S: IntoCStr>(name: S) -> Ref<Self> {
+ pub fn with_filename(name: &str) -> Ref<Self> {
let ret = FileMetadata::new();
ret.set_filename(name);
ret
@@ -75,7 +75,7 @@ impl FileMetadata {
}
}
- pub fn set_filename<S: IntoCStr>(&self, name: S) {
+ pub fn set_filename(&self, name: &str) {
let name = name.to_cstr();
unsafe {
@@ -107,7 +107,7 @@ impl FileMetadata {
self.is_database_backed_for_view_type("")
}
- pub fn is_database_backed_for_view_type<S: IntoCStr>(&self, view_type: S) -> bool {
+ pub fn is_database_backed_for_view_type(&self, view_type: &str) -> bool {
let view_type = view_type.to_cstr();
unsafe { BNIsBackedByDatabase(self.handle, view_type.as_ref().as_ptr() as *const _) }
@@ -121,11 +121,11 @@ impl FileMetadata {
let result = func();
match result {
Ok(t) => {
- self.commit_undo_actions(undo);
+ self.commit_undo_actions(&undo);
Ok(t)
}
Err(e) => {
- self.revert_undo_actions(undo);
+ self.revert_undo_actions(&undo);
Err(e)
}
}
@@ -135,14 +135,14 @@ impl FileMetadata {
unsafe { BnString::into_string(BNBeginUndoActions(self.handle, anonymous_allowed)) }
}
- pub fn commit_undo_actions<S: IntoCStr>(&self, id: S) {
+ pub fn commit_undo_actions(&self, id: &str) {
let id = id.to_cstr();
unsafe {
BNCommitUndoActions(self.handle, id.as_ref().as_ptr() as *const _);
}
}
- pub fn revert_undo_actions<S: IntoCStr>(&self, id: S) {
+ pub fn revert_undo_actions(&self, id: &str) {
let id = id.to_cstr();
unsafe {
BNRevertUndoActions(self.handle, id.as_ref().as_ptr() as *const _);
@@ -169,7 +169,7 @@ impl FileMetadata {
unsafe { BNGetCurrentOffset(self.handle) }
}
- pub fn navigate_to<S: IntoCStr>(&self, view: S, offset: u64) -> Result<(), ()> {
+ pub fn navigate_to(&self, view: &str, offset: u64) -> Result<(), ()> {
let view = view.to_cstr();
unsafe {
@@ -181,7 +181,7 @@ impl FileMetadata {
}
}
- pub fn view_of_type<S: IntoCStr>(&self, view: S) -> Option<Ref<BinaryView>> {
+ pub fn view_of_type(&self, view: &str) -> Option<Ref<BinaryView>> {
let view = view.to_cstr();
unsafe {
@@ -226,7 +226,7 @@ impl FileMetadata {
}
// TODO: Pass settings?
- pub fn create_database_with_progress<S: IntoCStr, P: ProgressCallback>(
+ pub fn create_database_with_progress<P: ProgressCallback>(
&self,
file_path: impl AsRef<Path>,
mut progress: P,
@@ -256,14 +256,11 @@ impl FileMetadata {
unsafe { BNSaveAutoSnapshot(raw_view.handle, ptr::null_mut() as *mut _) }
}
- pub fn open_database_for_configuration<S: IntoCStr>(
- &self,
- filename: S,
- ) -> Result<Ref<BinaryView>, ()> {
- let filename = filename.to_cstr();
+ pub fn open_database_for_configuration(&self, file: &Path) -> Result<Ref<BinaryView>, ()> {
+ let file = file.to_cstr();
unsafe {
let bv =
- BNOpenDatabaseForConfiguration(self.handle, filename.as_ref().as_ptr() as *const _);
+ BNOpenDatabaseForConfiguration(self.handle, file.as_ref().as_ptr() as *const _);
if bv.is_null() {
Err(())
@@ -273,11 +270,9 @@ impl FileMetadata {
}
}
- pub fn open_database<S: IntoCStr>(&self, filename: S) -> Result<Ref<BinaryView>, ()> {
- let filename = filename.to_cstr();
- let filename_ptr = filename.as_ptr();
-
- let view = unsafe { BNOpenExistingDatabase(self.handle, filename_ptr) };
+ pub fn open_database(&self, file: &Path) -> Result<Ref<BinaryView>, ()> {
+ let file = file.to_cstr();
+ let view = unsafe { BNOpenExistingDatabase(self.handle, file.as_ptr()) };
if view.is_null() {
Err(())
@@ -286,18 +281,17 @@ impl FileMetadata {
}
}
- pub fn open_database_with_progress<S: IntoCStr, P: ProgressCallback>(
+ pub fn open_database_with_progress<P: ProgressCallback>(
&self,
- filename: S,
+ file: &Path,
mut progress: P,
) -> Result<Ref<BinaryView>, ()> {
- let filename = filename.to_cstr();
- let filename_ptr = filename.as_ptr();
+ let file = file.to_cstr();
let view = unsafe {
BNOpenExistingDatabaseWithProgress(
self.handle,
- filename_ptr,
+ file.as_ptr(),
&mut progress as *mut P as *mut c_void,
Some(P::cb_progress_callback),
)
diff --git a/rust/src/function.rs b/rust/src/function.rs
index 5ebb84f6..c1c29873 100644
--- a/rust/src/function.rs
+++ b/rust/src/function.rs
@@ -372,7 +372,7 @@ impl Function {
unsafe { BnString::into_string(BNGetFunctionComment(self.handle)) }
}
- pub fn set_comment<S: IntoCStr>(&self, comment: S) {
+ pub fn set_comment(&self, comment: &str) {
let raw = comment.to_cstr();
unsafe {
@@ -394,7 +394,7 @@ impl Function {
unsafe { BnString::into_string(BNGetCommentForAddress(self.handle, addr)) }
}
- pub fn set_comment_at<S: IntoCStr>(&self, addr: u64, comment: S) {
+ pub fn set_comment_at(&self, addr: u64, comment: &str) {
let raw = comment.to_cstr();
unsafe {
@@ -1103,10 +1103,10 @@ impl Function {
/// let crash = bv.create_tag_type("Crashes", "🎯");
/// fun.add_tag(&crash, "Nullpointer dereference", Some(0x1337), false, None);
/// ```
- pub fn add_tag<S: IntoCStr>(
+ pub fn add_tag(
&self,
tag_type: &TagType,
- data: S,
+ data: &str,
addr: Option<u64>,
user: bool,
arch: Option<CoreArchitecture>,
@@ -1707,7 +1707,7 @@ impl Function {
operand: usize,
display_type: IntegerDisplayType,
arch: Option<CoreArchitecture>,
- enum_display_typeid: Option<impl IntoCStr>,
+ enum_display_typeid: Option<&str>,
) {
let arch = arch.unwrap_or_else(|| self.arch());
let enum_display_typeid = enum_display_typeid.map(IntoCStr::to_cstr);
diff --git a/rust/src/headless.rs b/rust/src/headless.rs
index 1e56321b..5910cd85 100644
--- a/rust/src/headless.rs
+++ b/rust/src/headless.rs
@@ -212,7 +212,7 @@ pub fn init_with_opts(options: InitializationOptions) -> Result<(), Initializati
}
}
- if let Some(license) = options.license {
+ if let Some(license) = &options.license {
// We were given a license override, use it!
set_license(Some(license));
}
diff --git a/rust/src/high_level_il/operation.rs b/rust/src/high_level_il/operation.rs
index 8f7e9d81..9c218227 100644
--- a/rust/src/high_level_il/operation.rs
+++ b/rust/src/high_level_il/operation.rs
@@ -20,7 +20,7 @@ impl GotoLabel {
unsafe { BnString::into_string(BNGetGotoLabelName(self.function.handle, self.target)) }
}
- fn set_name<S: IntoCStr>(&self, name: S) {
+ fn set_name(&self, name: &str) {
let raw = name.to_cstr();
unsafe {
BNSetUserGotoLabelName(
@@ -327,7 +327,7 @@ impl LiftedLabel {
self.target.name()
}
- pub fn set_name<S: IntoCStr>(&self, name: S) {
+ pub fn set_name(&self, name: &str) {
self.target.set_name(name)
}
}
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index 8d8fae13..7056e529 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -469,11 +469,18 @@ impl VersionInfo {
pub(crate) fn free_raw(value: BNVersionInfo) {
unsafe { BnString::free_raw(value.channel) };
}
+}
+
+impl TryFrom<&str> for VersionInfo {
+ type Error = ();
- pub fn from_string<S: IntoCStr>(string: S) -> Self {
- let string = string.to_cstr();
+ fn try_from(value: &str) -> Result<Self, Self::Error> {
+ let string = value.to_cstr();
let result = unsafe { BNParseVersionString(string.as_ptr()) };
- Self::from_owned_raw(result)
+ if result.build == 0 && result.channel.is_null() && result.major == 0 && result.minor == 0 {
+ return Err(());
+ }
+ Ok(Self::from_owned_raw(result))
}
}
@@ -529,13 +536,13 @@ pub fn license_count() -> i32 {
/// 1. Check the BN_LICENSE environment variable
/// 2. Check the Binary Ninja user directory for license.dat
#[cfg(not(feature = "demo"))]
-pub fn set_license<S: IntoCStr + Default>(license: Option<S>) {
+pub fn set_license(license: Option<&str>) {
let license = license.unwrap_or_default().to_cstr();
unsafe { BNSetLicense(license.as_ptr()) }
}
#[cfg(feature = "demo")]
-pub fn set_license<S: IntoCStr + Default>(_license: Option<S>) {}
+pub fn set_license(_license: Option<&str>) {}
pub fn product() -> String {
unsafe { BnString::into_string(BNGetProduct()) }
@@ -554,8 +561,8 @@ pub fn is_ui_enabled() -> bool {
unsafe { BNIsUIEnabled() }
}
-pub fn is_database<S: IntoCStr>(filename: S) -> bool {
- let filename = filename.to_cstr();
+pub fn is_database(file: &Path) -> bool {
+ let filename = file.to_cstr();
unsafe { BNIsDatabase(filename.as_ptr()) }
}
@@ -583,12 +590,12 @@ pub fn plugin_ui_abi_minimum_version() -> u32 {
BN_MINIMUM_UI_ABI_VERSION
}
-pub fn add_required_plugin_dependency<S: IntoCStr>(name: S) {
+pub fn add_required_plugin_dependency(name: &str) {
let raw_name = name.to_cstr();
unsafe { BNAddRequiredPluginDependency(raw_name.as_ptr()) };
}
-pub fn add_optional_plugin_dependency<S: IntoCStr>(name: S) {
+pub fn add_optional_plugin_dependency(name: &str) {
let raw_name = name.to_cstr();
unsafe { BNAddOptionalPluginDependency(raw_name.as_ptr()) };
}
diff --git a/rust/src/medium_level_il/function.rs b/rust/src/medium_level_il/function.rs
index 0b88c166..bdbe3159 100644
--- a/rust/src/medium_level_il/function.rs
+++ b/rust/src/medium_level_il/function.rs
@@ -121,11 +121,11 @@ impl MediumLevelILFunction {
unsafe { Array::new(raw_instr_idxs, count, self.to_owned()) }
}
- pub fn create_user_stack_var<'a, S: IntoCStr, C: Into<Conf<&'a Type>>>(
+ pub fn create_user_stack_var<'a, C: Into<Conf<&'a Type>>>(
self,
offset: i64,
var_type: C,
- name: S,
+ name: &str,
) {
let mut owned_raw_var_ty = Conf::<&Type>::into_raw(var_type.into());
let name = name.to_cstr();
@@ -143,11 +143,11 @@ impl MediumLevelILFunction {
unsafe { BNDeleteUserStackVariable(self.function().handle, offset) }
}
- pub fn create_user_var<'a, S: IntoCStr, C: Into<Conf<&'a Type>>>(
+ pub fn create_user_var<'a, C: Into<Conf<&'a Type>>>(
&self,
var: &Variable,
var_type: C,
- name: S,
+ name: &str,
ignore_disjoint_uses: bool,
) {
let raw_var = BNVariable::from(var);
@@ -273,11 +273,11 @@ impl MediumLevelILFunction {
Ok(())
}
- pub fn create_auto_stack_var<'a, T: Into<Conf<&'a Type>>, S: IntoCStr>(
+ pub fn create_auto_stack_var<'a, T: Into<Conf<&'a Type>>>(
&self,
offset: i64,
var_type: T,
- name: S,
+ name: &str,
) {
let mut owned_raw_var_ty = Conf::<&Type>::into_raw(var_type.into());
let name = name.to_cstr();
@@ -295,11 +295,11 @@ impl MediumLevelILFunction {
unsafe { BNDeleteAutoStackVariable(self.function().handle, offset) }
}
- pub fn create_auto_var<'a, S: IntoCStr, C: Into<Conf<&'a Type>>>(
+ pub fn create_auto_var<'a, C: Into<Conf<&'a Type>>>(
&self,
var: &Variable,
var_type: C,
- name: S,
+ name: &str,
ignore_disjoint_uses: bool,
) {
let raw_var = BNVariable::from(var);
diff --git a/rust/src/metadata.rs b/rust/src/metadata.rs
index 2ccd9d52..6cf1cbce 100644
--- a/rust/src/metadata.rs
+++ b/rust/src/metadata.rs
@@ -267,7 +267,7 @@ impl Metadata {
Ok(Some(unsafe { Self::ref_from_raw(ptr) }))
}
- pub fn get<S: IntoCStr>(&self, key: S) -> Result<Option<Ref<Metadata>>, ()> {
+ pub fn get(&self, key: &str) -> Result<Option<Ref<Metadata>>, ()> {
if self.get_type() != MetadataType::KeyValueDataType {
return Err(());
}
@@ -287,7 +287,7 @@ impl Metadata {
Ok(())
}
- pub fn insert<S: IntoCStr>(&self, key: S, value: &Metadata) -> Result<(), ()> {
+ pub fn insert(&self, key: &str, value: &Metadata) -> Result<(), ()> {
if self.get_type() != MetadataType::KeyValueDataType {
return Err(());
}
@@ -305,7 +305,7 @@ impl Metadata {
Ok(())
}
- pub fn remove_key<S: IntoCStr>(&self, key: S) -> Result<(), ()> {
+ pub fn remove_key(&self, key: &str) -> Result<(), ()> {
if self.get_type() != MetadataType::KeyValueDataType {
return Err(());
}
diff --git a/rust/src/platform.rs b/rust/src/platform.rs
index d7d3b990..013f709d 100644
--- a/rust/src/platform.rs
+++ b/rust/src/platform.rs
@@ -82,7 +82,7 @@ impl Platform {
Ref::new(Self { handle })
}
- pub fn by_name<S: IntoCStr>(name: S) -> Option<Ref<Self>> {
+ pub fn by_name(name: &str) -> Option<Ref<Self>> {
let raw_name = name.to_cstr();
unsafe {
let res = BNGetPlatformByName(raw_name.as_ptr());
@@ -113,7 +113,7 @@ impl Platform {
}
}
- pub fn list_by_os<S: IntoCStr>(name: S) -> Array<Platform> {
+ pub fn list_by_os(name: &str) -> Array<Platform> {
let raw_name = name.to_cstr();
unsafe {
@@ -124,7 +124,7 @@ impl Platform {
}
}
- pub fn list_by_os_and_arch<S: IntoCStr>(name: S, arch: &CoreArchitecture) -> Array<Platform> {
+ pub fn list_by_os_and_arch(name: &str, arch: &CoreArchitecture) -> Array<Platform> {
let raw_name = name.to_cstr();
unsafe {
@@ -145,7 +145,7 @@ impl Platform {
}
}
- pub fn new<A: Architecture, S: IntoCStr>(arch: &A, name: S) -> Ref<Self> {
+ pub fn new<A: Architecture>(arch: &A, name: &str) -> Ref<Self> {
let name = name.to_cstr();
unsafe {
let handle = BNCreatePlatform(arch.as_ref().handle, name.as_ptr());
@@ -173,7 +173,7 @@ impl Platform {
unsafe { TypeContainer::from_raw(type_container_ptr.unwrap()) }
}
- pub fn get_type_libraries_by_name<T: IntoCStr>(&self, name: T) -> Array<TypeLibrary> {
+ pub fn get_type_libraries_by_name(&self, name: &str) -> Array<TypeLibrary> {
let mut count = 0;
let name = name.to_cstr();
let result =
@@ -182,9 +182,8 @@ impl Platform {
unsafe { Array::new(result, count, ()) }
}
- pub fn register_os<S: IntoCStr>(&self, os: S) {
+ pub fn register_os(&self, os: &str) {
let os = os.to_cstr();
-
unsafe {
BNRegisterPlatform(os.as_ptr(), self.handle);
}
diff --git a/rust/src/project.rs b/rust/src/project.rs
index 7b6a263e..8b5f594a 100644
--- a/rust/src/project.rs
+++ b/rust/src/project.rs
@@ -35,21 +35,23 @@ impl Project {
unsafe { Array::new(result, count, ()) }
}
+ // TODO: Path here is actually local path?
/// Create a new project
///
/// * `path` - Path to the project directory (.bnpr)
/// * `name` - Name of the new project
- pub fn create<P: IntoCStr, S: IntoCStr>(path: P, name: S) -> Option<Ref<Self>> {
+ pub fn create(path: &str, name: &str) -> Option<Ref<Self>> {
let path_raw = path.to_cstr();
let name_raw = name.to_cstr();
let handle = unsafe { BNCreateProject(path_raw.as_ptr(), name_raw.as_ptr()) };
NonNull::new(handle).map(|h| unsafe { Self::ref_from_raw(h) })
}
+ // TODO: Path here is actually local path?
/// Open an existing project
///
/// * `path` - Path to the project directory (.bnpr) or project metadata file (.bnpm)
- pub fn open_project<P: IntoCStr>(path: P) -> Option<Ref<Self>> {
+ pub fn open_project(path: &str) -> Option<Ref<Self>> {
let path_raw = path.to_cstr();
let handle = unsafe { BNOpenProject(path_raw.as_ptr()) };
NonNull::new(handle).map(|h| unsafe { Self::ref_from_raw(h) })
@@ -94,7 +96,7 @@ impl Project {
}
/// Set the name of the project
- pub fn set_name<S: IntoCStr>(&self, value: S) {
+ pub fn set_name(&self, value: &str) {
let value = value.to_cstr();
unsafe { BNProjectSetName(self.handle.as_ptr(), value.as_ptr()) }
}
@@ -105,13 +107,13 @@ impl Project {
}
/// Set the description of the project
- pub fn set_description<S: IntoCStr>(&self, value: S) {
+ pub fn set_description(&self, value: &str) {
let value = value.to_cstr();
unsafe { BNProjectSetDescription(self.handle.as_ptr(), value.as_ptr()) }
}
/// Retrieves metadata stored under a key from the project
- pub fn query_metadata<S: IntoCStr>(&self, key: S) -> Ref<Metadata> {
+ pub fn query_metadata(&self, key: &str) -> Ref<Metadata> {
let key = key.to_cstr();
let result = unsafe { BNProjectQueryMetadata(self.handle.as_ptr(), key.as_ptr()) };
unsafe { Metadata::ref_from_raw(result) }
@@ -121,13 +123,13 @@ impl Project {
///
/// * `key` - Key under which to store the Metadata object
/// * `value` - Object to store
- pub fn store_metadata<S: IntoCStr>(&self, key: S, value: &Metadata) -> bool {
+ pub fn store_metadata(&self, key: &str, value: &Metadata) -> bool {
let key_raw = key.to_cstr();
unsafe { BNProjectStoreMetadata(self.handle.as_ptr(), key_raw.as_ptr(), value.handle) }
}
/// Removes the metadata associated with this `key` from the project
- pub fn remove_metadata<S: IntoCStr>(&self, key: S) {
+ pub fn remove_metadata(&self, key: &str) {
let key_raw = key.to_cstr();
unsafe { BNProjectRemoveMetadata(self.handle.as_ptr(), key_raw.as_ptr()) }
}
@@ -141,16 +143,12 @@ impl Project {
/// * `path` - Path to folder on disk
/// * `parent` - Parent folder in the project that will contain the new contents
/// * `description` - Description for created root folder
- pub fn create_folder_from_path<P, D>(
+ pub fn create_folder_from_path(
&self,
- path: P,
+ path: &str,
parent: Option<&ProjectFolder>,
- description: D,
- ) -> Result<Ref<ProjectFolder>, ()>
- where
- P: IntoCStr,
- D: IntoCStr,
- {
+ description: &str,
+ ) -> Result<Ref<ProjectFolder>, ()> {
self.create_folder_from_path_with_progress(path, parent, description, NoProgressCallback)
}
@@ -160,16 +158,14 @@ impl Project {
/// * `parent` - Parent folder in the project that will contain the new contents
/// * `description` - Description for created root folder
/// * `progress` - [`ProgressCallback`] that will be called as the [`ProjectFolder`] is being created
- pub fn create_folder_from_path_with_progress<P, D, PC>(
+ pub fn create_folder_from_path_with_progress<PC>(
&self,
- path: P,
+ path: &str,
parent: Option<&ProjectFolder>,
- description: D,
+ description: &str,
mut progress: PC,
) -> Result<Ref<ProjectFolder>, ()>
where
- P: IntoCStr,
- D: IntoCStr,
PC: ProgressCallback,
{
let path_raw = path.to_cstr();
@@ -194,16 +190,12 @@ impl Project {
/// * `parent` - Parent folder in the project that will contain the new folder
/// * `name` - Name for the created folder
/// * `description` - Description for created folder
- pub fn create_folder<N, D>(
+ pub fn create_folder(
&self,
parent: Option<&ProjectFolder>,
- name: N,
- description: D,
- ) -> Result<Ref<ProjectFolder>, ()>
- where
- N: IntoCStr,
- D: IntoCStr,
- {
+ name: &str,
+ description: &str,
+ ) -> Result<Ref<ProjectFolder>, ()> {
let name_raw = name.to_cstr();
let description_raw = description.to_cstr();
let parent_ptr = parent.map(|p| p.handle.as_ptr()).unwrap_or(null_mut());
@@ -224,18 +216,13 @@ impl Project {
/// * `name` - Name for the created folder
/// * `description` - Description for created folder
/// * `id` - id unique ID
- pub unsafe fn create_folder_unsafe<N, D, I>(
+ pub unsafe fn create_folder_unsafe(
&self,
parent: Option<&ProjectFolder>,
- name: N,
- description: D,
- id: I,
- ) -> Result<Ref<ProjectFolder>, ()>
- where
- N: IntoCStr,
- D: IntoCStr,
- I: IntoCStr,
- {
+ name: &str,
+ description: &str,
+ id: &str,
+ ) -> Result<Ref<ProjectFolder>, ()> {
let name_raw = name.to_cstr();
let description_raw = description.to_cstr();
let parent_ptr = parent.map(|p| p.handle.as_ptr()).unwrap_or(null_mut());
@@ -264,7 +251,7 @@ impl Project {
}
/// Retrieve a folder in the project by unique folder `id`
- pub fn folder_by_id<S: IntoCStr>(&self, id: S) -> Option<Ref<ProjectFolder>> {
+ pub fn folder_by_id(&self, id: &str) -> Option<Ref<ProjectFolder>> {
let raw_id = id.to_cstr();
let result = unsafe { BNProjectGetFolderById(self.handle.as_ptr(), raw_id.as_ptr()) };
let handle = NonNull::new(result)?;
@@ -282,17 +269,17 @@ impl Project {
///
/// * `folder` - [`ProjectFolder`] to delete recursively
/// * `progress` - [`ProgressCallback`] that will be called as objects get deleted
- pub fn delete_folder_with_progress<P: ProgressCallback>(
+ pub fn delete_folder_with_progress<PC: ProgressCallback>(
&self,
folder: &ProjectFolder,
- mut progress: P,
+ mut progress: PC,
) -> Result<(), ()> {
let result = unsafe {
BNProjectDeleteFolder(
self.handle.as_ptr(),
folder.handle.as_ptr(),
- &mut progress as *mut P as *mut c_void,
- Some(P::cb_progress_callback),
+ &mut progress as *mut PC as *mut c_void,
+ Some(PC::cb_progress_callback),
)
};
@@ -313,18 +300,13 @@ impl Project {
/// * `folder` - Folder to place the created file in
/// * `name` - Name to assign to the created file
/// * `description` - Description to assign to the created file
- pub fn create_file_from_path<P, N, D>(
+ pub fn create_file_from_path(
&self,
- path: P,
+ path: &str,
folder: Option<&ProjectFolder>,
- name: N,
- description: D,
- ) -> Result<Ref<ProjectFile>, ()>
- where
- P: IntoCStr,
- N: IntoCStr,
- D: IntoCStr,
- {
+ name: &str,
+ description: &str,
+ ) -> Result<Ref<ProjectFile>, ()> {
self.create_file_from_path_with_progress(
path,
folder,
@@ -341,18 +323,15 @@ impl Project {
/// * `name` - Name to assign to the created file
/// * `description` - Description to assign to the created file
/// * `progress` - [`ProgressCallback`] that will be called as the [`ProjectFile`] is being added
- pub fn create_file_from_path_with_progress<P, N, D, PC>(
+ pub fn create_file_from_path_with_progress<PC>(
&self,
- path: P,
+ path: &str,
folder: Option<&ProjectFolder>,
- name: N,
- description: D,
+ name: &str,
+ description: &str,
mut progress: PC,
) -> Result<Ref<ProjectFile>, ()>
where
- P: IntoCStr,
- N: IntoCStr,
- D: IntoCStr,
PC: ProgressCallback,
{
let path_raw = path.to_cstr();
@@ -382,21 +361,15 @@ impl Project {
/// * `description` - Description to assign to the created file
/// * `id` - id unique ID
/// * `creation_time` - Creation time of the file
- pub unsafe fn create_file_from_path_unsafe<P, N, D, I>(
+ pub unsafe fn create_file_from_path_unsafe(
&self,
- path: P,
+ path: &str,
folder: Option<&ProjectFolder>,
- name: N,
- description: D,
- id: I,
+ name: &str,
+ description: &str,
+ id: &str,
creation_time: SystemTime,
- ) -> Result<Ref<ProjectFile>, ()>
- where
- P: IntoCStr,
- N: IntoCStr,
- D: IntoCStr,
- I: IntoCStr,
- {
+ ) -> Result<Ref<ProjectFile>, ()> {
self.create_file_from_path_unsafe_with_progress(
path,
folder,
@@ -418,21 +391,17 @@ impl Project {
/// * `creation_time` - Creation time of the file
/// * `progress` - [`ProgressCallback`] that will be called as the [`ProjectFile`] is being created
#[allow(clippy::too_many_arguments)]
- pub unsafe fn create_file_from_path_unsafe_with_progress<P, N, D, I, PC>(
+ pub unsafe fn create_file_from_path_unsafe_with_progress<PC>(
&self,
- path: P,
+ path: &str,
folder: Option<&ProjectFolder>,
- name: N,
- description: D,
- id: I,
+ name: &str,
+ description: &str,
+ id: &str,
creation_time: SystemTime,
mut progress: PC,
) -> Result<Ref<ProjectFile>, ()>
where
- P: IntoCStr,
- N: IntoCStr,
- D: IntoCStr,
- I: IntoCStr,
PC: ProgressCallback,
{
let path_raw = path.to_cstr();
@@ -463,17 +432,13 @@ impl Project {
/// * `folder` - Folder to place the created file in
/// * `name` - Name to assign to the created file
/// * `description` - Description to assign to the created file
- pub fn create_file<N, D>(
+ pub fn create_file(
&self,
contents: &[u8],
folder: Option<&ProjectFolder>,
- name: N,
- description: D,
- ) -> Result<Ref<ProjectFile>, ()>
- where
- N: IntoCStr,
- D: IntoCStr,
- {
+ name: &str,
+ description: &str,
+ ) -> Result<Ref<ProjectFile>, ()> {
self.create_file_with_progress(contents, folder, name, description, NoProgressCallback)
}
@@ -484,18 +449,16 @@ impl Project {
/// * `name` - Name to assign to the created file
/// * `description` - Description to assign to the created file
/// * `progress` - [`ProgressCallback`] that will be called as the [`ProjectFile`] is being created
- pub fn create_file_with_progress<N, D, P>(
+ pub fn create_file_with_progress<PC>(
&self,
contents: &[u8],
folder: Option<&ProjectFolder>,
- name: N,
- description: D,
- mut progress: P,
+ name: &str,
+ description: &str,
+ mut progress: PC,
) -> Result<Ref<ProjectFile>, ()>
where
- N: IntoCStr,
- D: IntoCStr,
- P: ProgressCallback,
+ PC: ProgressCallback,
{
let name_raw = name.to_cstr();
let description_raw = description.to_cstr();
@@ -509,8 +472,8 @@ impl Project {
folder_ptr,
name_raw.as_ptr(),
description_raw.as_ptr(),
- &mut progress as *mut P as *mut c_void,
- Some(P::cb_progress_callback),
+ &mut progress as *mut PC as *mut c_void,
+ Some(PC::cb_progress_callback),
);
Ok(ProjectFile::ref_from_raw(NonNull::new(result).ok_or(())?))
}
@@ -524,20 +487,15 @@ impl Project {
/// * `description` - Description to assign to the created file
/// * `id` - id unique ID
/// * `creation_time` - Creation time of the file
- pub unsafe fn create_file_unsafe<N, D, I>(
+ pub unsafe fn create_file_unsafe(
&self,
contents: &[u8],
folder: Option<&ProjectFolder>,
- name: N,
- description: D,
- id: I,
+ name: &str,
+ description: &str,
+ id: &str,
creation_time: SystemTime,
- ) -> Result<Ref<ProjectFile>, ()>
- where
- N: IntoCStr,
- D: IntoCStr,
- I: IntoCStr,
- {
+ ) -> Result<Ref<ProjectFile>, ()> {
self.create_file_unsafe_with_progress(
contents,
folder,
@@ -559,21 +517,18 @@ impl Project {
/// * `creation_time` - Creation time of the file
/// * `progress` - [`ProgressCallback`] that will be called as the [`ProjectFile`] is being created
#[allow(clippy::too_many_arguments)]
- pub unsafe fn create_file_unsafe_with_progress<N, D, I, P>(
+ pub unsafe fn create_file_unsafe_with_progress<PC>(
&self,
contents: &[u8],
folder: Option<&ProjectFolder>,
- name: N,
- description: D,
- id: I,
+ name: &str,
+ description: &str,
+ id: &str,
creation_time: SystemTime,
- mut progress: P,
+ mut progress: PC,
) -> Result<Ref<ProjectFile>, ()>
where
- N: IntoCStr,
- D: IntoCStr,
- I: IntoCStr,
- P: ProgressCallback,
+ PC: ProgressCallback,
{
let name_raw = name.to_cstr();
let description_raw = description.to_cstr();
@@ -590,8 +545,8 @@ impl Project {
description_raw.as_ptr(),
id_raw.as_ptr(),
systime_to_bntime(creation_time).unwrap(),
- &mut progress as *mut P as *mut c_void,
- Some(P::cb_progress_callback),
+ &mut progress as *mut PC as *mut c_void,
+ Some(PC::cb_progress_callback),
);
Ok(ProjectFile::ref_from_raw(NonNull::new(result).ok_or(())?))
}
@@ -606,7 +561,7 @@ impl Project {
}
/// Retrieve a file in the project by unique `id`
- pub fn file_by_id<S: IntoCStr>(&self, id: S) -> Option<Ref<ProjectFile>> {
+ pub fn file_by_id(&self, id: &str) -> Option<Ref<ProjectFile>> {
let raw_id = id.to_cstr();
let result = unsafe { BNProjectGetFileById(self.handle.as_ptr(), raw_id.as_ptr()) };
let handle = NonNull::new(result)?;
@@ -614,7 +569,7 @@ impl Project {
}
/// Retrieve a file in the project by the `path` on disk
- pub fn file_by_path<S: IntoCStr>(&self, path: S) -> Option<Ref<ProjectFile>> {
+ pub fn file_by_path(&self, path: &str) -> Option<Ref<ProjectFile>> {
let path_raw = path.to_cstr();
let result =
unsafe { BNProjectGetFileByPathOnDisk(self.handle.as_ptr(), path_raw.as_ptr()) };
diff --git a/rust/src/project/file.rs b/rust/src/project/file.rs
index 4a1d6fec..3b3e48f7 100644
--- a/rust/src/project/file.rs
+++ b/rust/src/project/file.rs
@@ -9,6 +9,7 @@ use binaryninjacore_sys::{
BNProjectFileSetFolder, BNProjectFileSetName,
};
use std::fmt::Debug;
+use std::path::Path;
use std::ptr::{null_mut, NonNull};
use std::time::SystemTime;
@@ -56,7 +57,7 @@ impl ProjectFile {
}
/// Set the name of this file
- pub fn set_name<S: IntoCStr>(&self, value: S) -> bool {
+ pub fn set_name(&self, value: &str) -> bool {
let value_raw = value.to_cstr();
unsafe { BNProjectFileSetName(self.handle.as_ptr(), value_raw.as_ptr()) }
}
@@ -67,7 +68,7 @@ impl ProjectFile {
}
/// Set the description of this file
- pub fn set_description<S: IntoCStr>(&self, value: S) -> bool {
+ pub fn set_description(&self, value: &str) -> bool {
let value_raw = value.to_cstr();
unsafe { BNProjectFileSetDescription(self.handle.as_ptr(), value_raw.as_ptr()) }
}
@@ -92,8 +93,8 @@ impl ProjectFile {
/// Export this file to disk, `true' if the export succeeded
///
- /// * `dest` - Destination path for the exported contents
- pub fn export<S: IntoCStr>(&self, dest: S) -> bool {
+ /// * `dest` - Destination file path for the exported contents, passing a directory will append the file name.
+ pub fn export(&self, dest: &Path) -> bool {
let dest_raw = dest.to_cstr();
unsafe { BNProjectFileExport(self.handle.as_ptr(), dest_raw.as_ptr()) }
}
diff --git a/rust/src/project/folder.rs b/rust/src/project/folder.rs
index acb663fb..d5d95e76 100644
--- a/rust/src/project/folder.rs
+++ b/rust/src/project/folder.rs
@@ -10,6 +10,7 @@ use binaryninjacore_sys::{
};
use std::ffi::c_void;
use std::fmt::Debug;
+use std::path::Path;
use std::ptr::{null_mut, NonNull};
#[repr(transparent)]
@@ -46,7 +47,7 @@ impl ProjectFolder {
}
/// Set the name of this folder
- pub fn set_name<S: IntoCStr>(&self, value: S) -> bool {
+ pub fn set_name(&self, value: &str) -> bool {
let value_raw = value.to_cstr();
unsafe { BNProjectFolderSetName(self.handle.as_ptr(), value_raw.as_ptr()) }
}
@@ -57,7 +58,7 @@ impl ProjectFolder {
}
/// Set the description of this folder
- pub fn set_description<S: IntoCStr>(&self, value: S) -> bool {
+ pub fn set_description(&self, value: &str) -> bool {
let value_raw = value.to_cstr();
unsafe { BNProjectFolderSetDescription(self.handle.as_ptr(), value_raw.as_ptr()) }
}
@@ -74,22 +75,19 @@ impl ProjectFolder {
unsafe { BNProjectFolderSetParent(self.handle.as_ptr(), folder_handle) }
}
- // TODO: Take Path?
/// Recursively export this folder to disk, returns `true' if the export succeeded
///
/// * `dest` - Destination path for the exported contents
- pub fn export<S: IntoCStr>(&self, dest: S) -> bool {
+ pub fn export(&self, dest: &Path) -> bool {
self.export_with_progress(dest, NoProgressCallback)
}
- // TODO: Take Path?
/// Recursively export this folder to disk, returns `true' if the export succeeded
///
/// * `dest` - Destination path for the exported contents
/// * `progress` - [`ProgressCallback`] that will be called as contents are exporting
- pub fn export_with_progress<S, P>(&self, dest: S, mut progress: P) -> bool
+ pub fn export_with_progress<P>(&self, dest: &Path, mut progress: P) -> bool
where
- S: IntoCStr,
P: ProgressCallback,
{
let dest_raw = dest.to_cstr();
diff --git a/rust/src/relocation.rs b/rust/src/relocation.rs
index 756c76bf..2b24279b 100644
--- a/rust/src/relocation.rs
+++ b/rust/src/relocation.rs
@@ -402,9 +402,8 @@ unsafe impl RefCountable for CoreRelocationHandler {
}
}
-pub(crate) fn register_relocation_handler<S, R, F>(arch: &CoreArchitecture, name: S, func: F)
+pub(crate) fn register_relocation_handler<R, F>(arch: &CoreArchitecture, name: &str, func: F)
where
- S: IntoCStr,
R: 'static + RelocationHandler<Handle = CustomRelocationHandlerHandle<R>> + Send + Sync + Sized,
F: FnOnce(CustomRelocationHandlerHandle<R>, CoreRelocationHandler) -> R,
{
diff --git a/rust/src/render_layer.rs b/rust/src/render_layer.rs
index 3fd94a3a..08553552 100644
--- a/rust/src/render_layer.rs
+++ b/rust/src/render_layer.rs
@@ -61,8 +61,8 @@ impl Default for RenderLayerDefaultState {
}
/// Register a [`RenderLayer`] with the API.
-pub fn register_render_layer<S: IntoCStr, T: RenderLayer>(
- name: S,
+pub fn register_render_layer<T: RenderLayer>(
+ name: &str,
render_layer: T,
default_state: RenderLayerDefaultState,
) -> (&'static mut T, CoreRenderLayer) {
@@ -299,7 +299,7 @@ impl CoreRenderLayer {
unsafe { Array::new(result, count, ()) }
}
- pub fn render_layer_by_name<S: IntoCStr>(name: S) -> Option<CoreRenderLayer> {
+ pub fn render_layer_by_name(name: &str) -> Option<CoreRenderLayer> {
let name_raw = name.to_cstr();
let result = unsafe { BNGetRenderLayerByName(name_raw.as_ptr()) };
NonNull::new(result).map(Self::from_raw)
diff --git a/rust/src/repository.rs b/rust/src/repository.rs
index 8d9a8f40..a29be323 100644
--- a/rust/src/repository.rs
+++ b/rust/src/repository.rs
@@ -3,6 +3,7 @@ mod plugin;
use std::ffi::c_char;
use std::fmt::Debug;
+use std::path::{Path, PathBuf};
use std::ptr::NonNull;
use binaryninjacore_sys::*;
@@ -38,10 +39,11 @@ impl Repository {
}
/// String local path to store the given plugin repository
- pub fn path(&self) -> String {
+ pub fn path(&self) -> PathBuf {
let result = unsafe { BNRepositoryGetRepoPath(self.handle.as_ptr()) };
assert!(!result.is_null());
- unsafe { BnString::into_string(result as *mut c_char) }
+ let result_str = unsafe { BnString::into_string(result as *mut c_char) };
+ PathBuf::from(result_str)
}
/// List of RepoPlugin objects contained within this repository
@@ -52,18 +54,18 @@ impl Repository {
unsafe { Array::new(result, count, ()) }
}
- pub fn plugin_by_path<S: IntoCStr>(&self, path: S) -> Option<Ref<RepositoryPlugin>> {
+ pub fn plugin_by_path(&self, path: &Path) -> Option<Ref<RepositoryPlugin>> {
let path = path.to_cstr();
let result = unsafe { BNRepositoryGetPluginByPath(self.handle.as_ptr(), path.as_ptr()) };
NonNull::new(result).map(|h| unsafe { RepositoryPlugin::ref_from_raw(h) })
}
- // TODO: Make this a PathBuf?
/// String full path the repository
- pub fn full_path(&self) -> String {
+ pub fn full_path(&self) -> PathBuf {
let result = unsafe { BNRepositoryGetPluginsPath(self.handle.as_ptr()) };
assert!(!result.is_null());
- unsafe { BnString::into_string(result as *mut c_char) }
+ let result_str = unsafe { BnString::into_string(result as *mut c_char) };
+ PathBuf::from(result_str)
}
}
diff --git a/rust/src/repository/manager.rs b/rust/src/repository/manager.rs
index 42d8aa42..cf0118ad 100644
--- a/rust/src/repository/manager.rs
+++ b/rust/src/repository/manager.rs
@@ -8,6 +8,7 @@ use binaryninjacore_sys::{
BNRepositoryManagerGetDefaultRepository, BNRepositoryManagerGetRepositories,
};
use std::fmt::Debug;
+use std::path::Path;
use std::ptr::NonNull;
/// Keeps track of all the repositories and keeps the `enabled_plugins.json`
@@ -28,7 +29,7 @@ impl RepositoryManager {
Ref::new(Self { handle })
}
- pub fn new<S: IntoCStr>(plugins_path: S) -> Ref<Self> {
+ pub fn new(plugins_path: &str) -> Ref<Self> {
let plugins_path = plugins_path.to_cstr();
let result = unsafe { BNCreateRepositoryManager(plugins_path.as_ptr()) };
unsafe { Self::ref_from_raw(NonNull::new(result).unwrap()) }
@@ -59,7 +60,7 @@ impl RepositoryManager {
/// * `repository_path` - path to where the repository will be stored on disk locally
///
/// Returns true if the repository was successfully added, false otherwise.
- pub fn add_repository<U: IntoCStr, P: IntoCStr>(&self, url: U, repository_path: P) -> bool {
+ pub fn add_repository(&self, url: &str, repository_path: &Path) -> bool {
let url = url.to_cstr();
let repo_path = repository_path.to_cstr();
unsafe {
@@ -67,7 +68,7 @@ impl RepositoryManager {
}
}
- pub fn repository_by_path<P: IntoCStr>(&self, path: P) -> Option<Repository> {
+ pub fn repository_by_path(&self, path: &Path) -> Option<Repository> {
let path = path.to_cstr();
let result =
unsafe { BNRepositoryGetRepositoryByPath(self.handle.as_ptr(), path.as_ptr()) };
diff --git a/rust/src/repository/plugin.rs b/rust/src/repository/plugin.rs
index 82309e79..e0ab9679 100644
--- a/rust/src/repository/plugin.rs
+++ b/rust/src/repository/plugin.rs
@@ -5,6 +5,7 @@ use crate::VersionInfo;
use binaryninjacore_sys::*;
use std::ffi::c_char;
use std::fmt::Debug;
+use std::path::PathBuf;
use std::ptr::NonNull;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
@@ -112,17 +113,19 @@ impl RepositoryPlugin {
}
/// Relative path from the base of the repository to the actual plugin
- pub fn path(&self) -> String {
+ pub fn path(&self) -> PathBuf {
let result = unsafe { BNPluginGetPath(self.handle.as_ptr()) };
assert!(!result.is_null());
- unsafe { BnString::into_string(result as *mut c_char) }
+ let result_str = unsafe { BnString::into_string(result as *mut c_char) };
+ PathBuf::from(result_str)
}
/// Optional sub-directory the plugin code lives in as a relative path from the plugin root
- pub fn subdir(&self) -> String {
+ pub fn subdir(&self) -> PathBuf {
let result = unsafe { BNPluginGetSubdir(self.handle.as_ptr()) };
assert!(!result.is_null());
- unsafe { BnString::into_string(result as *mut c_char) }
+ let result_str = unsafe { BnString::into_string(result as *mut c_char) };
+ PathBuf::from(result_str)
}
/// Dependencies required for installing this plugin
diff --git a/rust/src/secrets_provider.rs b/rust/src/secrets_provider.rs
index 5924b9fb..a310b08e 100644
--- a/rust/src/secrets_provider.rs
+++ b/rust/src/secrets_provider.rs
@@ -49,7 +49,7 @@ impl CoreSecretsProvider {
}
/// Retrieve a provider by name
- pub fn by_name<S: IntoCStr>(name: S) -> Option<CoreSecretsProvider> {
+ pub fn by_name(name: &str) -> Option<CoreSecretsProvider> {
let name = name.to_cstr();
let result = unsafe { BNGetSecretsProviderByName(name.as_ptr()) };
NonNull::new(result).map(|h| unsafe { Self::from_raw(h) })
@@ -62,27 +62,27 @@ impl CoreSecretsProvider {
}
/// Check if data for a specific key exists, but do not retrieve it
- pub fn has_data<S: IntoCStr>(&self, key: S) -> bool {
+ pub fn has_data(&self, key: &str) -> bool {
let key = key.to_cstr();
unsafe { BNSecretsProviderHasData(self.handle.as_ptr(), key.as_ptr()) }
}
/// Retrieve data for the given key, if it exists
- pub fn get_data<S: IntoCStr>(&self, key: S) -> String {
+ pub fn get_data(&self, key: &str) -> String {
let key = key.to_cstr();
let result = unsafe { BNGetSecretsProviderData(self.handle.as_ptr(), key.as_ptr()) };
unsafe { BnString::into_string(result) }
}
/// Store data with the given key
- pub fn store_data<K: IntoCStr, V: IntoCStr>(&self, key: K, value: V) -> bool {
+ pub fn store_data(&self, key: &str, value: &str) -> bool {
let key = key.to_cstr();
let value = value.to_cstr();
unsafe { BNStoreSecretsProviderData(self.handle.as_ptr(), key.as_ptr(), value.as_ptr()) }
}
/// Delete stored data with the given key
- pub fn delete_data<S: IntoCStr>(&self, key: S) -> bool {
+ pub fn delete_data(&self, key: &str) -> bool {
let key = key.to_cstr();
unsafe { BNDeleteSecretsProviderData(self.handle.as_ptr(), key.as_ptr()) }
}
diff --git a/rust/src/settings.rs b/rust/src/settings.rs
index 35f7b7a0..0047f570 100644
--- a/rust/src/settings.rs
+++ b/rust/src/settings.rs
@@ -44,7 +44,7 @@ impl Settings {
Self::new_with_id(GLOBAL_INSTANCE_ID)
}
- pub fn new_with_id<S: IntoCStr>(instance_id: S) -> Ref<Self> {
+ pub fn new_with_id(instance_id: &str) -> Ref<Self> {
let instance_id = instance_id.to_cstr();
unsafe {
let handle = BNCreateSettings(instance_id.as_ptr());
@@ -53,7 +53,7 @@ impl Settings {
}
}
- pub fn set_resource_id<S: IntoCStr>(&self, resource_id: S) {
+ pub fn set_resource_id(&self, resource_id: &str) {
let resource_id = resource_id.to_cstr();
unsafe { BNSettingsSetResourceId(self.handle, resource_id.as_ptr()) };
}
@@ -62,20 +62,16 @@ impl Settings {
unsafe { BnString::into_string(BNSettingsSerializeSchema(self.handle)) }
}
- pub fn deserialize_schema<S: IntoCStr>(&self, schema: S) -> bool {
+ pub fn deserialize_schema(&self, schema: &str) -> bool {
self.deserialize_schema_with_scope(schema, SettingsScope::SettingsAutoScope)
}
- pub fn deserialize_schema_with_scope<S: IntoCStr>(
- &self,
- schema: S,
- scope: SettingsScope,
- ) -> bool {
+ pub fn deserialize_schema_with_scope(&self, schema: &str, scope: SettingsScope) -> bool {
let schema = schema.to_cstr();
unsafe { BNSettingsDeserializeSchema(self.handle, schema.as_ptr(), scope, true) }
}
- pub fn contains<S: IntoCStr>(&self, key: S) -> bool {
+ pub fn contains(&self, key: &str) -> bool {
let key = key.to_cstr();
unsafe { BNSettingsContains(self.handle, key.as_ptr()) }
@@ -90,11 +86,11 @@ impl Settings {
// TODO Update the settings API to take an optional BinaryView or Function. Separate functions or...?
- pub fn get_bool<S: IntoCStr>(&self, key: S) -> bool {
+ pub fn get_bool(&self, key: &str) -> bool {
self.get_bool_with_opts(key, &mut QueryOptions::default())
}
- pub fn get_bool_with_opts<S: IntoCStr>(&self, key: S, options: &mut QueryOptions) -> bool {
+ pub fn get_bool_with_opts(&self, key: &str, options: &mut QueryOptions) -> bool {
let key = key.to_cstr();
let view_ptr = match options.view.as_ref() {
Some(view) => view.handle,
@@ -115,11 +111,11 @@ impl Settings {
}
}
- pub fn get_double<S: IntoCStr>(&self, key: S) -> f64 {
+ pub fn get_double(&self, key: &str) -> f64 {
self.get_double_with_opts(key, &mut QueryOptions::default())
}
- pub fn get_double_with_opts<S: IntoCStr>(&self, key: S, options: &mut QueryOptions) -> f64 {
+ pub fn get_double_with_opts(&self, key: &str, options: &mut QueryOptions) -> f64 {
let key = key.to_cstr();
let view_ptr = match options.view.as_ref() {
Some(view) => view.handle,
@@ -140,11 +136,11 @@ impl Settings {
}
}
- pub fn get_integer<S: IntoCStr>(&self, key: S) -> u64 {
+ pub fn get_integer(&self, key: &str) -> u64 {
self.get_integer_with_opts(key, &mut QueryOptions::default())
}
- pub fn get_integer_with_opts<S: IntoCStr>(&self, key: S, options: &mut QueryOptions) -> u64 {
+ pub fn get_integer_with_opts(&self, key: &str, options: &mut QueryOptions) -> u64 {
let key = key.to_cstr();
let view_ptr = match options.view.as_ref() {
Some(view) => view.handle,
@@ -165,11 +161,11 @@ impl Settings {
}
}
- pub fn get_string<S: IntoCStr>(&self, key: S) -> String {
+ pub fn get_string(&self, key: &str) -> String {
self.get_string_with_opts(key, &mut QueryOptions::default())
}
- pub fn get_string_with_opts<S: IntoCStr>(&self, key: S, options: &mut QueryOptions) -> String {
+ pub fn get_string_with_opts(&self, key: &str, options: &mut QueryOptions) -> String {
let key = key.to_cstr();
let view_ptr = match options.view.as_ref() {
Some(view) => view.handle,
@@ -190,13 +186,13 @@ impl Settings {
}
}
- pub fn get_string_list<S: IntoCStr>(&self, key: S) -> Array<BnString> {
+ pub fn get_string_list(&self, key: &str) -> Array<BnString> {
self.get_string_list_with_opts(key, &mut QueryOptions::default())
}
- pub fn get_string_list_with_opts<S: IntoCStr>(
+ pub fn get_string_list_with_opts(
&self,
- key: S,
+ key: &str,
options: &mut QueryOptions,
) -> Array<BnString> {
let key = key.to_cstr();
@@ -225,11 +221,11 @@ impl Settings {
}
}
- pub fn get_json<S: IntoCStr>(&self, key: S) -> String {
+ pub fn get_json(&self, key: &str) -> String {
self.get_json_with_opts(key, &mut QueryOptions::default())
}
- pub fn get_json_with_opts<S: IntoCStr>(&self, key: S, options: &mut QueryOptions) -> String {
+ pub fn get_json_with_opts(&self, key: &str, options: &mut QueryOptions) -> String {
let key = key.to_cstr();
let view_ptr = match options.view.as_ref() {
Some(view) => view.handle,
@@ -250,11 +246,11 @@ impl Settings {
}
}
- pub fn set_bool<S: IntoCStr>(&self, key: S, value: bool) {
+ pub fn set_bool(&self, key: &str, value: bool) {
self.set_bool_with_opts(key, value, &QueryOptions::default())
}
- pub fn set_bool_with_opts<S: IntoCStr>(&self, key: S, value: bool, options: &QueryOptions) {
+ pub fn set_bool_with_opts(&self, key: &str, value: bool, options: &QueryOptions) {
let key = key.to_cstr();
let view_ptr = match options.view.as_ref() {
Some(view) => view.handle,
@@ -276,10 +272,10 @@ impl Settings {
}
}
- pub fn set_double<S: IntoCStr>(&self, key: S, value: f64) {
+ pub fn set_double(&self, key: &str, value: f64) {
self.set_double_with_opts(key, value, &QueryOptions::default())
}
- pub fn set_double_with_opts<S: IntoCStr>(&self, key: S, value: f64, options: &QueryOptions) {
+ pub fn set_double_with_opts(&self, key: &str, value: f64, options: &QueryOptions) {
let key = key.to_cstr();
let view_ptr = match options.view.as_ref() {
Some(view) => view.handle,
@@ -301,11 +297,11 @@ impl Settings {
}
}
- pub fn set_integer<S: IntoCStr>(&self, key: S, value: u64) {
+ pub fn set_integer(&self, key: &str, value: u64) {
self.set_integer_with_opts(key, value, &QueryOptions::default())
}
- pub fn set_integer_with_opts<S: IntoCStr>(&self, key: S, value: u64, options: &QueryOptions) {
+ pub fn set_integer_with_opts(&self, key: &str, value: u64, options: &QueryOptions) {
let key = key.to_cstr();
let view_ptr = match options.view.as_ref() {
Some(view) => view.handle,
@@ -327,16 +323,11 @@ impl Settings {
}
}
- pub fn set_string<S1: IntoCStr, S2: IntoCStr>(&self, key: S1, value: S2) {
+ pub fn set_string(&self, key: &str, value: &str) {
self.set_string_with_opts(key, value, &QueryOptions::default())
}
- pub fn set_string_with_opts<S1: IntoCStr, S2: IntoCStr>(
- &self,
- key: S1,
- value: S2,
- options: &QueryOptions,
- ) {
+ pub fn set_string_with_opts(&self, key: &str, value: &str, options: &QueryOptions) {
let key = key.to_cstr();
let value = value.to_cstr();
let view_ptr = match options.view.as_ref() {
@@ -359,22 +350,18 @@ impl Settings {
}
}
- pub fn set_string_list<S1: IntoCStr, S2: IntoCStr, I: Iterator<Item = S2>>(
- &self,
- key: S1,
- value: I,
- ) -> bool {
+ pub fn set_string_list<I: IntoIterator<Item = String>>(&self, key: &str, value: I) -> bool {
self.set_string_list_with_opts(key, value, &QueryOptions::default())
}
- pub fn set_string_list_with_opts<S1: IntoCStr, S2: IntoCStr, I: Iterator<Item = S2>>(
+ pub fn set_string_list_with_opts<I: IntoIterator<Item = String>>(
&self,
- key: S1,
+ key: &str,
value: I,
options: &QueryOptions,
) -> bool {
let key = key.to_cstr();
- let raw_list: Vec<_> = value.map(|s| s.to_cstr()).collect();
+ let raw_list: Vec<_> = value.into_iter().map(|s| s.to_cstr()).collect();
let mut raw_list_ptr: Vec<_> = raw_list.iter().map(|s| s.as_ptr()).collect();
let view_ptr = match options.view.as_ref() {
@@ -398,16 +385,11 @@ impl Settings {
}
}
- pub fn set_json<S1: IntoCStr, S2: IntoCStr>(&self, key: S1, value: S2) -> bool {
+ pub fn set_json(&self, key: &str, value: &str) -> bool {
self.set_json_with_opts(key, value, &QueryOptions::default())
}
- pub fn set_json_with_opts<S1: IntoCStr, S2: IntoCStr>(
- &self,
- key: S1,
- value: S2,
- options: &QueryOptions,
- ) -> bool {
+ pub fn set_json_with_opts(&self, key: &str, value: &str, options: &QueryOptions) -> bool {
let key = key.to_cstr();
let value = value.to_cstr();
let view_ptr = match options.view.as_ref() {
@@ -430,7 +412,7 @@ impl Settings {
}
}
- pub fn get_property_string<S: IntoCStr>(&self, key: S, property: S) -> String {
+ pub fn get_property_string(&self, key: &str, property: &str) -> String {
let key = key.to_cstr();
let property = property.to_cstr();
unsafe {
@@ -442,7 +424,7 @@ impl Settings {
}
}
- pub fn get_property_string_list<S: IntoCStr>(&self, key: S, property: S) -> Array<BnString> {
+ pub fn get_property_string_list(&self, key: &str, property: &str) -> Array<BnString> {
let key = key.to_cstr();
let property = property.to_cstr();
let mut size: usize = 0;
@@ -460,7 +442,7 @@ impl Settings {
}
}
- pub fn update_bool_property<S: IntoCStr>(&self, key: S, property: S, value: bool) {
+ pub fn update_bool_property(&self, key: &str, property: &str, value: bool) {
let key = key.to_cstr();
let property = property.to_cstr();
unsafe {
@@ -468,7 +450,7 @@ impl Settings {
}
}
- pub fn update_integer_property<S: IntoCStr>(&self, key: S, property: S, value: u64) {
+ pub fn update_integer_property(&self, key: &str, property: &str, value: u64) {
let key = key.to_cstr();
let property = property.to_cstr();
unsafe {
@@ -476,7 +458,7 @@ impl Settings {
}
}
- pub fn update_double_property<S: IntoCStr>(&self, key: S, property: S, value: f64) {
+ pub fn update_double_property(&self, key: &str, property: &str, value: f64) {
let key = key.to_cstr();
let property = property.to_cstr();
unsafe {
@@ -484,7 +466,7 @@ impl Settings {
}
}
- pub fn update_string_property<S: IntoCStr>(&self, key: S, property: S, value: S) {
+ pub fn update_string_property(&self, key: &str, property: &str, value: &str) {
let key = key.to_cstr();
let property = property.to_cstr();
let value = value.to_cstr();
@@ -498,15 +480,15 @@ impl Settings {
}
}
- pub fn update_string_list_property<S: IntoCStr, I: Iterator<Item = S>>(
+ pub fn update_string_list_property<I: IntoIterator<Item = String>>(
&self,
- key: S,
- property: S,
+ key: &str,
+ property: &str,
value: I,
) {
let key = key.to_cstr();
let property = property.to_cstr();
- let raw_list: Vec<_> = value.map(|s| s.to_cstr()).collect();
+ let raw_list: Vec<_> = value.into_iter().map(|s| s.to_cstr()).collect();
let mut raw_list_ptr: Vec<_> = raw_list.iter().map(|s| s.as_ptr()).collect();
unsafe {
@@ -520,18 +502,14 @@ impl Settings {
}
}
- pub fn register_group<S1: IntoCStr, S2: IntoCStr>(&self, group: S1, title: S2) -> bool {
+ pub fn register_group(&self, group: &str, title: &str) -> bool {
let group = group.to_cstr();
let title = title.to_cstr();
unsafe { BNSettingsRegisterGroup(self.handle, group.as_ptr(), title.as_ptr()) }
}
- pub fn register_setting_json<S1: IntoCStr, S2: IntoCStr>(
- &self,
- group: S1,
- properties: S2,
- ) -> bool {
+ pub fn register_setting_json(&self, group: &str, properties: &str) -> bool {
let group = group.to_cstr();
let properties = properties.to_cstr();
diff --git a/rust/src/tags.rs b/rust/src/tags.rs
index e7a2d44d..a8c4d5d4 100644
--- a/rust/src/tags.rs
+++ b/rust/src/tags.rs
@@ -42,7 +42,7 @@ impl Tag {
Ref::new(Self { handle })
}
- pub fn new<S: IntoCStr>(t: &TagType, data: S) -> Ref<Self> {
+ pub fn new(t: &TagType, data: &str) -> Ref<Self> {
let data = data.to_cstr();
unsafe { Self::ref_from_raw(BNCreateTag(t.handle, data.as_ptr())) }
}
@@ -59,7 +59,7 @@ impl Tag {
unsafe { TagType::ref_from_raw(BNTagGetType(self.handle)) }
}
- pub fn set_data<S: IntoCStr>(&self, data: S) {
+ pub fn set_data(&self, data: &str) {
let data = data.to_cstr();
unsafe {
BNTagSetData(self.handle, data.as_ptr());
@@ -134,7 +134,7 @@ impl TagType {
Ref::new(Self { handle })
}
- pub fn create<N: IntoCStr, I: IntoCStr>(view: &BinaryView, name: N, icon: I) -> Ref<Self> {
+ pub fn create(view: &BinaryView, name: &str, icon: &str) -> Ref<Self> {
let tag_type = unsafe { Self::ref_from_raw(BNCreateTagType(view.handle)) };
tag_type.set_name(name);
tag_type.set_icon(icon);
@@ -149,7 +149,7 @@ impl TagType {
unsafe { BnString::into_string(BNTagTypeGetIcon(self.handle)) }
}
- pub fn set_icon<S: IntoCStr>(&self, icon: S) {
+ pub fn set_icon(&self, icon: &str) {
let icon = icon.to_cstr();
unsafe {
BNTagTypeSetIcon(self.handle, icon.as_ptr());
@@ -160,7 +160,7 @@ impl TagType {
unsafe { BnString::into_string(BNTagTypeGetName(self.handle)) }
}
- pub fn set_name<S: IntoCStr>(&self, name: S) {
+ pub fn set_name(&self, name: &str) {
let name = name.to_cstr();
unsafe {
BNTagTypeSetName(self.handle, name.as_ptr());
@@ -179,7 +179,7 @@ impl TagType {
unsafe { BNTagTypeGetType(self.handle) }
}
- pub fn set_type<S: IntoCStr>(&self, t: S) {
+ pub fn set_type(&self, t: &str) {
let t = t.to_cstr();
unsafe {
BNTagTypeSetName(self.handle, t.as_ptr());
diff --git a/rust/src/type_archive.rs b/rust/src/type_archive.rs
index 84e9fdee..f4d1087c 100644
--- a/rust/src/type_archive.rs
+++ b/rust/src/type_archive.rs
@@ -82,9 +82,9 @@ impl TypeArchive {
/// Create a Type Archive at the given path and id, returning None if it could not be created.
///
/// If the file has already been created and is not a valid type archive this will return `None`.
- pub fn create_with_id<I: IntoCStr>(
+ pub fn create_with_id(
path: impl AsRef<Path>,
- id: I,
+ id: &str,
platform: &Platform,
) -> Option<Ref<TypeArchive>> {
let raw_path = path.as_ref().to_cstr();
@@ -95,7 +95,7 @@ impl TypeArchive {
}
/// Get a reference to the Type Archive with the known id, if one exists.
- pub fn lookup_by_id<S: IntoCStr>(id: S) -> Option<Ref<TypeArchive>> {
+ pub fn lookup_by_id(id: &str) -> Option<Ref<TypeArchive>> {
let id = id.to_cstr();
let handle = unsafe { BNLookupTypeArchiveById(id.as_ptr()) };
NonNull::new(handle).map(|handle| unsafe { TypeArchive::ref_from_raw(handle) })
@@ -104,19 +104,16 @@ impl TypeArchive {
/// Get the path to the Type Archive's file
pub fn path(&self) -> Option<PathBuf> {
let result = unsafe { BNGetTypeArchivePath(self.handle.as_ptr()) };
- match result.is_null() {
- false => {
- let path_str = unsafe { BnString::into_string(result) };
- Some(PathBuf::from(path_str))
- }
- true => None,
- }
+ assert!(!result.is_null());
+ let path_str = unsafe { BnString::into_string(result) };
+ Some(PathBuf::from(path_str))
}
/// Get the guid for a Type Archive
- pub fn id(&self) -> Option<BnString> {
+ pub fn id(&self) -> BnString {
let result = unsafe { BNGetTypeArchiveId(self.handle.as_ptr()) };
- (!result.is_null()).then(|| unsafe { BnString::from_raw(result) })
+ assert!(!result.is_null());
+ unsafe { BnString::from_raw(result) }
}
/// Get the associated Platform for a Type Archive
@@ -150,7 +147,7 @@ impl TypeArchive {
}
/// Get the ids of the parents to the given snapshot
- pub fn get_snapshot_parent_ids<S: IntoCStr>(
+ pub fn get_snapshot_parent_ids(
&self,
snapshot: &TypeArchiveSnapshotId,
) -> Option<Array<BnString>> {
@@ -166,7 +163,7 @@ impl TypeArchive {
}
/// Get the ids of the children to the given snapshot
- pub fn get_snapshot_child_ids<S: IntoCStr>(
+ pub fn get_snapshot_child_ids(
&self,
snapshot: &TypeArchiveSnapshotId,
) -> Option<Array<BnString>> {
@@ -219,7 +216,7 @@ impl TypeArchive {
/// * `new_name` - New type name
pub fn rename_type(&self, old_name: QualifiedName, new_name: QualifiedName) -> bool {
if let Some(id) = self.get_type_id(old_name) {
- self.rename_type_by_id(id, new_name)
+ self.rename_type_by_id(&id, new_name)
} else {
false
}
@@ -229,7 +226,7 @@ impl TypeArchive {
///
/// * `id` - Old id of type in archive
/// * `new_name` - New type name
- pub fn rename_type_by_id<S: IntoCStr>(&self, id: S, new_name: QualifiedName) -> bool {
+ pub fn rename_type_by_id(&self, id: &str, new_name: QualifiedName) -> bool {
let id = id.to_cstr();
let raw_name = QualifiedName::into_raw(new_name);
let result =
@@ -241,14 +238,14 @@ impl TypeArchive {
/// Delete an existing type in the type archive.
pub fn delete_type(&self, name: QualifiedName) -> bool {
if let Some(type_id) = self.get_type_id(name) {
- self.delete_type_by_id(type_id)
+ self.delete_type_by_id(&type_id)
} else {
false
}
}
/// Delete an existing type in the type archive.
- pub fn delete_type_by_id<S: IntoCStr>(&self, id: S) -> bool {
+ pub fn delete_type_by_id(&self, id: &str) -> bool {
let id = id.to_cstr();
unsafe { BNDeleteTypeArchiveType(self.handle.as_ptr(), id.as_ptr()) }
}
@@ -256,7 +253,7 @@ impl TypeArchive {
/// Retrieve a stored type in the archive
///
/// * `name` - Type name
- pub fn get_type_by_name<S: IntoCStr>(&self, name: QualifiedName) -> Option<Ref<Type>> {
+ pub fn get_type_by_name(&self, name: QualifiedName) -> Option<Ref<Type>> {
self.get_type_by_name_from_snapshot(name, &TypeArchiveSnapshotId::unset())
}
@@ -284,7 +281,7 @@ impl TypeArchive {
/// Retrieve a stored type in the archive by id
///
/// * `id` - Type id
- pub fn get_type_by_id<I: IntoCStr>(&self, id: I) -> Option<Ref<Type>> {
+ pub fn get_type_by_id(&self, id: &str) -> Option<Ref<Type>> {
self.get_type_by_id_from_snapshot(id, &TypeArchiveSnapshotId::unset())
}
@@ -292,9 +289,9 @@ impl TypeArchive {
///
/// * `id` - Type id
/// * `snapshot` - Snapshot id to search for types
- pub fn get_type_by_id_from_snapshot<I: IntoCStr>(
+ pub fn get_type_by_id_from_snapshot(
&self,
- id: I,
+ id: &str,
snapshot: &TypeArchiveSnapshotId,
) -> Option<Ref<Type>> {
let id = id.to_cstr();
@@ -311,7 +308,7 @@ impl TypeArchive {
/// Retrieve a type's name by its id
///
/// * `id` - Type id
- pub fn get_type_name_by_id<I: IntoCStr>(&self, id: I) -> QualifiedName {
+ pub fn get_type_name_by_id(&self, id: &str) -> QualifiedName {
self.get_type_name_by_id_from_snapshot(id, &TypeArchiveSnapshotId::unset())
}
@@ -319,9 +316,9 @@ impl TypeArchive {
///
/// * `id` - Type id
/// * `snapshot` - Snapshot id to search for types
- pub fn get_type_name_by_id_from_snapshot<I: IntoCStr>(
+ pub fn get_type_name_by_id_from_snapshot(
&self,
- id: I,
+ id: &str,
snapshot: &TypeArchiveSnapshotId,
) -> QualifiedName {
let id = id.to_cstr();
@@ -338,7 +335,7 @@ impl TypeArchive {
/// Retrieve a type's id by its name
///
/// * `name` - Type name
- pub fn get_type_id(&self, name: QualifiedName) -> Option<BnString> {
+ pub fn get_type_id(&self, name: QualifiedName) -> Option<String> {
self.get_type_id_from_snapshot(name, &TypeArchiveSnapshotId::unset())
}
@@ -350,7 +347,7 @@ impl TypeArchive {
&self,
name: QualifiedName,
snapshot: &TypeArchiveSnapshotId,
- ) -> Option<BnString> {
+ ) -> Option<String> {
let raw_name = QualifiedName::into_raw(name);
let result = unsafe {
BNGetTypeArchiveTypeId(
@@ -360,7 +357,7 @@ impl TypeArchive {
)
};
QualifiedName::free_raw(raw_name);
- (!result.is_null()).then(|| unsafe { BnString::from_raw(result) })
+ (!result.is_null()).then(|| unsafe { BnString::into_string(result) })
}
/// Retrieve all stored types in the archive at a snapshot
@@ -465,7 +462,7 @@ impl TypeArchive {
/// Get all types a given type references directly
///
/// * `id` - Source type id
- pub fn get_outgoing_direct_references<I: IntoCStr>(&self, id: I) -> Array<BnString> {
+ pub fn get_outgoing_direct_references(&self, id: &str) -> Array<BnString> {
self.get_outgoing_direct_references_from_snapshot(id, &TypeArchiveSnapshotId::unset())
}
@@ -473,9 +470,9 @@ impl TypeArchive {
///
/// * `id` - Source type id
/// * `snapshot` - Snapshot id to search for types
- pub fn get_outgoing_direct_references_from_snapshot<I: IntoCStr>(
+ pub fn get_outgoing_direct_references_from_snapshot(
&self,
- id: I,
+ id: &str,
snapshot: &TypeArchiveSnapshotId,
) -> Array<BnString> {
let id = id.to_cstr();
@@ -495,7 +492,7 @@ impl TypeArchive {
/// Get all types a given type references, and any types that the referenced types reference
///
/// * `id` - Source type id
- pub fn get_outgoing_recursive_references<I: IntoCStr>(&self, id: I) -> Array<BnString> {
+ pub fn get_outgoing_recursive_references(&self, id: &str) -> Array<BnString> {
self.get_outgoing_recursive_references_from_snapshot(id, &TypeArchiveSnapshotId::unset())
}
@@ -503,9 +500,9 @@ impl TypeArchive {
///
/// * `id` - Source type id
/// * `snapshot` - Snapshot id to search for types
- pub fn get_outgoing_recursive_references_from_snapshot<I: IntoCStr>(
+ pub fn get_outgoing_recursive_references_from_snapshot(
&self,
- id: I,
+ id: &str,
snapshot: &TypeArchiveSnapshotId,
) -> Array<BnString> {
let id = id.to_cstr();
@@ -525,7 +522,7 @@ impl TypeArchive {
/// Get all types that reference a given type
///
/// * `id` - Target type id
- pub fn get_incoming_direct_references<I: IntoCStr>(&self, id: I) -> Array<BnString> {
+ pub fn get_incoming_direct_references(&self, id: &str) -> Array<BnString> {
self.get_incoming_direct_references_with_snapshot(id, &TypeArchiveSnapshotId::unset())
}
@@ -533,9 +530,9 @@ impl TypeArchive {
///
/// * `id` - Target type id
/// * `snapshot` - Snapshot id to search for types
- pub fn get_incoming_direct_references_with_snapshot<I: IntoCStr>(
+ pub fn get_incoming_direct_references_with_snapshot(
&self,
- id: I,
+ id: &str,
snapshot: &TypeArchiveSnapshotId,
) -> Array<BnString> {
let id = id.to_cstr();
@@ -555,7 +552,7 @@ impl TypeArchive {
/// Get all types that reference a given type, and all types that reference them, recursively
///
/// * `id` - Target type id
- pub fn get_incoming_recursive_references<I: IntoCStr>(&self, id: I) -> Array<BnString> {
+ pub fn get_incoming_recursive_references(&self, id: &str) -> Array<BnString> {
self.get_incoming_recursive_references_with_snapshot(id, &TypeArchiveSnapshotId::unset())
}
@@ -563,9 +560,9 @@ impl TypeArchive {
///
/// * `id` - Target type id
/// * `snapshot` - Snapshot id to search for types, or empty string to search the latest snapshot
- pub fn get_incoming_recursive_references_with_snapshot<I: IntoCStr>(
+ pub fn get_incoming_recursive_references_with_snapshot(
&self,
- id: I,
+ id: &str,
snapshot: &TypeArchiveSnapshotId,
) -> Array<BnString> {
let id = id.to_cstr();
@@ -583,7 +580,7 @@ impl TypeArchive {
}
/// Look up a metadata entry in the archive
- pub fn query_metadata<S: IntoCStr>(&self, key: S) -> Option<Ref<Metadata>> {
+ pub fn query_metadata(&self, key: &str) -> Option<Ref<Metadata>> {
let key = key.to_cstr();
let result = unsafe { BNTypeArchiveQueryMetadata(self.handle.as_ptr(), key.as_ptr()) };
(!result.is_null()).then(|| unsafe { Metadata::ref_from_raw(result) })
@@ -593,7 +590,7 @@ impl TypeArchive {
///
/// * `key` - key value to associate the Metadata object with
/// * `md` - object to store.
- pub fn store_metadata<S: IntoCStr>(&self, key: S, md: &Metadata) {
+ pub fn store_metadata(&self, key: &str, md: &Metadata) {
let key = key.to_cstr();
let result =
unsafe { BNTypeArchiveStoreMetadata(self.handle.as_ptr(), key.as_ptr(), md.handle) };
@@ -601,13 +598,13 @@ impl TypeArchive {
}
/// Delete a given metadata entry in the archive from the `key`
- pub fn remove_metadata<S: IntoCStr>(&self, key: S) -> bool {
+ pub fn remove_metadata(&self, key: &str) -> bool {
let key = key.to_cstr();
unsafe { BNTypeArchiveRemoveMetadata(self.handle.as_ptr(), key.as_ptr()) }
}
/// Turn a given `snapshot` id into a data stream
- pub fn serialize_snapshot<S: IntoCStr>(&self, snapshot: &TypeArchiveSnapshotId) -> DataBuffer {
+ pub fn serialize_snapshot(&self, snapshot: &TypeArchiveSnapshotId) -> DataBuffer {
let result = unsafe {
BNTypeArchiveSerializeSnapshot(
self.handle.as_ptr(),
@@ -678,9 +675,8 @@ impl TypeArchive {
unsafe { BNCloseTypeArchive(self.handle.as_ptr()) }
}
- // TODO: Make this AsRef<Path>?
/// Determine if `file` is a Type Archive
- pub fn is_type_archive<P: IntoCStr>(file: P) -> bool {
+ pub fn is_type_archive(file: &Path) -> bool {
let file = file.to_cstr();
unsafe { BNIsTypeArchive(file.as_ptr()) }
}
@@ -699,13 +695,12 @@ impl TypeArchive {
/// * `parents` - Parent snapshot ids
///
/// Returns Created snapshot id
- pub fn new_snapshot_transaction<P, F>(
+ pub fn new_snapshot_transaction<F>(
&self,
mut function: F,
parents: &[TypeArchiveSnapshotId],
) -> TypeArchiveSnapshotId
where
- P: IntoCStr,
F: FnMut(&TypeArchiveSnapshotId) -> bool,
{
unsafe extern "C" fn cb_callback<F: FnMut(&TypeArchiveSnapshotId) -> bool>(
@@ -744,20 +739,15 @@ impl TypeArchive {
///
/// Returns Snapshot id, if merge was successful, otherwise the List of
/// conflicting type ids
- pub fn merge_snapshots<B, F, S, M, MI, MK>(
+ pub fn merge_snapshots<M>(
&self,
- base_snapshot: B,
- first_snapshot: F,
- second_snapshot: S,
+ base_snapshot: &str,
+ first_snapshot: &str,
+ second_snapshot: &str,
merge_conflicts: M,
) -> Result<BnString, Array<BnString>>
where
- B: IntoCStr,
- F: IntoCStr,
- S: IntoCStr,
- M: IntoIterator<Item = (MI, MK)>,
- MI: IntoCStr,
- MK: IntoCStr,
+ M: IntoIterator<Item = (String, String)>,
{
self.merge_snapshots_with_progress(
base_snapshot,
@@ -778,22 +768,17 @@ impl TypeArchive {
///
/// Returns Snapshot id, if merge was successful, otherwise the List of
/// conflicting type ids
- pub fn merge_snapshots_with_progress<B, F, S, M, MI, MK, P>(
+ pub fn merge_snapshots_with_progress<M, PC>(
&self,
- base_snapshot: B,
- first_snapshot: F,
- second_snapshot: S,
+ base_snapshot: &str,
+ first_snapshot: &str,
+ second_snapshot: &str,
merge_conflicts: M,
- mut progress: P,
+ mut progress: PC,
) -> Result<BnString, Array<BnString>>
where
- B: IntoCStr,
- F: IntoCStr,
- S: IntoCStr,
- M: IntoIterator<Item = (MI, MK)>,
- MI: IntoCStr,
- MK: IntoCStr,
- P: ProgressCallback,
+ M: IntoIterator<Item = (String, String)>,
+ PC: ProgressCallback,
{
let base_snapshot = base_snapshot.to_cstr();
let first_snapshot = first_snapshot.to_cstr();
@@ -823,8 +808,8 @@ impl TypeArchive {
&mut conflicts_errors,
&mut conflicts_errors_count,
&mut result,
- Some(P::cb_progress_callback),
- &mut progress as *mut P as *mut c_void,
+ Some(PC::cb_progress_callback),
+ &mut progress as *mut PC as *mut c_void,
)
};
@@ -867,7 +852,7 @@ impl Eq for TypeArchive {}
impl Hash for TypeArchive {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
- (self.handle.as_ptr() as usize).hash(state);
+ self.id().hash(state);
}
}
@@ -1140,10 +1125,10 @@ impl TypeArchiveMergeConflict {
TypeArchiveSnapshotId(id)
}
- // TODO: This needs documentation!
- pub fn success<S: IntoCStr>(&self, value: S) -> bool {
- let value = value.to_cstr();
- unsafe { BNTypeArchiveMergeConflictSuccess(self.handle.as_ptr(), value.as_ptr()) }
+ /// Call this when you've resolved the conflict to save the result.
+ pub fn success(&self, result: &str) -> bool {
+ let result = result.to_cstr();
+ unsafe { BNTypeArchiveMergeConflictSuccess(self.handle.as_ptr(), result.as_ptr()) }
}
}
diff --git a/rust/src/type_container.rs b/rust/src/type_container.rs
index 2257a297..d68fc9c0 100644
--- a/rust/src/type_container.rs
+++ b/rust/src/type_container.rs
@@ -137,7 +137,7 @@ impl TypeContainer {
/// (by id) to use the new name.
///
/// Returns true if the type was renamed.
- pub fn rename_type<T: Into<QualifiedName>, S: IntoCStr>(&self, name: T, type_id: S) -> bool {
+ pub fn rename_type<T: Into<QualifiedName>>(&self, name: T, type_id: &str) -> bool {
let type_id = type_id.to_cstr();
let raw_name = QualifiedName::into_raw(name.into());
let success =
@@ -150,7 +150,7 @@ impl TypeContainer {
/// not specified and you may end up with broken references if any still exist.
///
/// Returns true if the type was deleted.
- pub fn delete_type<S: IntoCStr>(&self, type_id: S) -> bool {
+ pub fn delete_type(&self, type_id: &str) -> bool {
let type_id = type_id.to_cstr();
unsafe { BNTypeContainerDeleteType(self.handle.as_ptr(), type_id.as_ptr()) }
}
@@ -158,19 +158,19 @@ impl TypeContainer {
/// Get the unique id of the type in the Type Container with the given name.
///
/// If no type with that name exists, returns None.
- pub fn type_id<T: Into<QualifiedName>>(&self, name: T) -> Option<BnString> {
+ pub fn type_id<T: Into<QualifiedName>>(&self, name: T) -> Option<String> {
let mut result = std::ptr::null_mut();
let raw_name = QualifiedName::into_raw(name.into());
let success =
unsafe { BNTypeContainerGetTypeId(self.handle.as_ptr(), &raw_name, &mut result) };
QualifiedName::free_raw(raw_name);
- success.then(|| unsafe { BnString::from_raw(result) })
+ success.then(|| unsafe { BnString::into_string(result) })
}
/// Get the unique name of the type in the Type Container with the given id.
///
/// If no type with that id exists, returns None.
- pub fn type_name<S: IntoCStr>(&self, type_id: S) -> Option<QualifiedName> {
+ pub fn type_name(&self, type_id: &str) -> Option<QualifiedName> {
let type_id = type_id.to_cstr();
let mut result = BNQualifiedName::default();
let success = unsafe {
@@ -182,7 +182,7 @@ impl TypeContainer {
/// Get the definition of the type in the Type Container with the given id.
///
/// If no type with that id exists, returns None.
- pub fn type_by_id<S: IntoCStr>(&self, type_id: S) -> Option<Ref<Type>> {
+ pub fn type_by_id(&self, type_id: &str) -> Option<Ref<Type>> {
let type_id = type_id.to_cstr();
let mut result = std::ptr::null_mut();
let success = unsafe {
@@ -283,9 +283,9 @@ impl TypeContainer {
///
/// * `source` - Source code to parse
/// * `import_dependencies` - If Type Library / Type Archive types should be imported during parsing
- pub fn parse_type_string<S: IntoCStr>(
+ pub fn parse_type_string(
&self,
- source: S,
+ source: &str,
import_dependencies: bool,
) -> Result<QualifiedNameAndType, Array<TypeParserError>> {
let source = source.to_cstr();
@@ -319,23 +319,18 @@ impl TypeContainer {
/// * `include_dirs` - List of directories to include in the header search path
/// * `auto_type_source` - Source of types if used for automatically generated types
/// * `import_dependencies` - If Type Library / Type Archive types should be imported during parsing
- pub fn parse_types_from_source<S, F, O, D, A>(
+ pub fn parse_types_from_source<O, I>(
&self,
- source: S,
- filename: F,
+ source: &str,
+ filename: &str,
options: O,
- include_directories: D,
- auto_type_source: A,
+ include_directories: I,
+ auto_type_source: &str,
import_dependencies: bool,
) -> Result<TypeParserResult, Array<TypeParserError>>
where
- S: IntoCStr,
- F: IntoCStr,
- O: IntoIterator,
- O::Item: IntoCStr,
- D: IntoIterator,
- D::Item: IntoCStr,
- A: IntoCStr,
+ O: IntoIterator<Item = String>,
+ I: IntoIterator<Item = String>,
{
let source = source.to_cstr();
let filename = filename.to_cstr();
diff --git a/rust/src/type_library.rs b/rust/src/type_library.rs
index 29634c38..6d09abfa 100644
--- a/rust/src/type_library.rs
+++ b/rust/src/type_library.rs
@@ -1,7 +1,5 @@
use binaryninjacore_sys::*;
-use core::{ffi, mem, ptr};
-
use crate::{
architecture::CoreArchitecture,
metadata::Metadata,
@@ -10,6 +8,8 @@ use crate::{
string::{BnString, IntoCStr},
types::{QualifiedName, QualifiedNameAndType, Type},
};
+use core::{ffi, mem, ptr};
+use std::path::Path;
#[repr(transparent)]
pub struct TypeLibrary {
@@ -42,7 +42,7 @@ impl TypeLibrary {
}
/// Creates an empty type library object with a random GUID and the provided name.
- pub fn new<S: IntoCStr>(arch: CoreArchitecture, name: S) -> TypeLibrary {
+ pub fn new(arch: CoreArchitecture, name: &str) -> TypeLibrary {
let name = name.to_cstr();
let new_lib =
unsafe { BNNewTypeLibrary(arch.handle, name.as_ref().as_ptr() as *const ffi::c_char) };
@@ -57,9 +57,9 @@ impl TypeLibrary {
}
/// Decompresses a type library file to a file on disk.
- pub fn decompress_to_file<P: IntoCStr, O: IntoCStr>(path: P, output: O) -> bool {
+ pub fn decompress_to_file(path: &Path, output_path: &Path) -> bool {
let path = path.to_cstr();
- let output = output.to_cstr();
+ let output = output_path.to_cstr();
unsafe {
BNTypeLibraryDecompressToFile(
path.as_ref().as_ptr() as *const ffi::c_char,
@@ -69,7 +69,7 @@ impl TypeLibrary {
}
/// Loads a finalized type library instance from file
- pub fn load_from_file<S: IntoCStr>(path: S) -> Option<TypeLibrary> {
+ pub fn load_from_file(path: &Path) -> Option<TypeLibrary> {
let path = path.to_cstr();
let handle =
unsafe { BNLoadTypeLibraryFromFile(path.as_ref().as_ptr() as *const ffi::c_char) };
@@ -77,7 +77,7 @@ impl TypeLibrary {
}
/// Saves a finalized type library instance to file
- pub fn write_to_file<S: IntoCStr>(&self, path: S) -> bool {
+ pub fn write_to_file(&self, path: &Path) -> bool {
let path = path.to_cstr();
unsafe {
BNWriteTypeLibraryToFile(self.as_raw(), path.as_ref().as_ptr() as *const ffi::c_char)
@@ -86,7 +86,7 @@ impl TypeLibrary {
/// Looks up the first type library found with a matching name. Keep in mind that names are not
/// necessarily unique.
- pub fn from_name<S: IntoCStr>(arch: CoreArchitecture, name: S) -> Option<TypeLibrary> {
+ pub fn from_name(arch: CoreArchitecture, name: &str) -> Option<TypeLibrary> {
let name = name.to_cstr();
let handle = unsafe {
BNLookupTypeLibraryByName(arch.handle, name.as_ref().as_ptr() as *const ffi::c_char)
@@ -95,7 +95,7 @@ impl TypeLibrary {
}
/// Attempts to grab a type library associated with the provided Architecture and GUID pair
- pub fn from_guid<S: IntoCStr>(arch: CoreArchitecture, guid: S) -> Option<TypeLibrary> {
+ pub fn from_guid(arch: CoreArchitecture, guid: &str) -> Option<TypeLibrary> {
let guid = guid.to_cstr();
let handle = unsafe {
BNLookupTypeLibraryByGuid(arch.handle, guid.as_ref().as_ptr() as *const ffi::c_char)
@@ -117,7 +117,7 @@ impl TypeLibrary {
}
/// Sets the name of a type library instance that has not been finalized
- pub fn set_name<S: IntoCStr>(&self, value: S) {
+ pub fn set_name(&self, value: &str) {
let value = value.to_cstr();
unsafe {
BNSetTypeLibraryName(self.as_raw(), value.as_ref().as_ptr() as *const ffi::c_char)
@@ -135,7 +135,7 @@ impl TypeLibrary {
}
/// Sets the dependency name of a type library instance that has not been finalized
- pub fn set_dependency_name<S: IntoCStr>(&self, value: S) {
+ pub fn set_dependency_name(&self, value: &str) {
let value = value.to_cstr();
unsafe {
BNSetTypeLibraryDependencyName(
@@ -152,7 +152,7 @@ impl TypeLibrary {
}
/// Sets the GUID of a type library instance that has not been finalized
- pub fn set_guid<S: IntoCStr>(&self, value: S) {
+ pub fn set_guid(&self, value: &str) {
let value = value.to_cstr();
unsafe {
BNSetTypeLibraryGuid(self.as_raw(), value.as_ref().as_ptr() as *const ffi::c_char)
@@ -168,7 +168,7 @@ impl TypeLibrary {
}
/// Adds an extra name to this type library used during library lookups and dependency resolution
- pub fn add_alternate_name<S: IntoCStr>(&self, value: S) {
+ pub fn add_alternate_name(&self, value: &str) {
let value = value.to_cstr();
unsafe {
BNAddTypeLibraryAlternateName(
@@ -212,7 +212,7 @@ impl TypeLibrary {
}
/// Retrieves a metadata associated with the given key stored in the type library
- pub fn query_metadata<S: IntoCStr>(&self, key: S) -> Option<Metadata> {
+ pub fn query_metadata(&self, key: &str) -> Option<Metadata> {
let key = key.to_cstr();
let result = unsafe {
BNTypeLibraryQueryMetadata(self.as_raw(), key.as_ref().as_ptr() as *const ffi::c_char)
@@ -231,7 +231,7 @@ impl TypeLibrary {
///
/// * `key` - key value to associate the Metadata object with
/// * `md` - object to store.
- pub fn store_metadata<S: IntoCStr>(&self, key: S, md: &Metadata) {
+ pub fn store_metadata(&self, key: &str, md: &Metadata) {
let key = key.to_cstr();
unsafe {
BNTypeLibraryStoreMetadata(
@@ -243,7 +243,7 @@ impl TypeLibrary {
}
/// Removes the metadata associated with key from the current type library.
- pub fn remove_metadata<S: IntoCStr>(&self, key: S) {
+ pub fn remove_metadata(&self, key: &str) {
let key = key.to_cstr();
unsafe {
BNTypeLibraryRemoveMetadata(self.as_raw(), key.as_ref().as_ptr() as *const ffi::c_char)
@@ -299,7 +299,7 @@ impl TypeLibrary {
/// Use this api with extreme caution.
///
/// </div>
- pub fn add_type_source<S: IntoCStr>(&self, name: QualifiedName, source: S) {
+ pub fn add_type_source(&self, name: QualifiedName, source: &str) {
let source = source.to_cstr();
let mut raw_name = QualifiedName::into_raw(name);
unsafe {
diff --git a/rust/src/type_parser.rs b/rust/src/type_parser.rs
index e2134b2b..0ce46a50 100644
--- a/rust/src/type_parser.rs
+++ b/rust/src/type_parser.rs
@@ -14,8 +14,8 @@ pub type TypeParserErrorSeverity = BNTypeParserErrorSeverity;
pub type TypeParserOption = BNTypeParserOption;
/// Register a custom parser with the API
-pub fn register_type_parser<S: IntoCStr, T: TypeParser>(
- name: S,
+pub fn register_type_parser<T: TypeParser>(
+ name: &str,
parser: T,
) -> (&'static mut T, CoreTypeParser) {
let parser = Box::leak(Box::new(parser));
@@ -51,7 +51,7 @@ impl CoreTypeParser {
unsafe { Array::new(result, count, ()) }
}
- pub fn parser_by_name<S: IntoCStr>(name: S) -> Option<CoreTypeParser> {
+ pub fn parser_by_name(name: &str) -> Option<CoreTypeParser> {
let name_raw = name.to_cstr();
let result = unsafe { BNGetTypeParserByName(name_raw.as_ptr()) };
NonNull::new(result).map(|x| unsafe { Self::from_raw(x) })
diff --git a/rust/src/type_printer.rs b/rust/src/type_printer.rs
index 206478a2..c9bec609 100644
--- a/rust/src/type_printer.rs
+++ b/rust/src/type_printer.rs
@@ -15,8 +15,8 @@ pub type TokenEscapingType = BNTokenEscapingType;
pub type TypeDefinitionLineType = BNTypeDefinitionLineType;
/// Register a custom parser with the API
-pub fn register_type_printer<S: IntoCStr, T: TypePrinter>(
- name: S,
+pub fn register_type_printer<T: TypePrinter>(
+ name: &str,
parser: T,
) -> (&'static mut T, CoreTypePrinter) {
let parser = Box::leak(Box::new(parser));
@@ -57,7 +57,7 @@ impl CoreTypePrinter {
unsafe { Array::new(result, count, ()) }
}
- pub fn printer_by_name<S: IntoCStr>(name: S) -> Option<CoreTypePrinter> {
+ pub fn printer_by_name(name: &str) -> Option<CoreTypePrinter> {
let name_raw = name.to_cstr();
let result = unsafe { BNGetTypePrinterByName(name_raw.as_ptr()) };
NonNull::new(result).map(|x| unsafe { Self::from_raw(x) })
@@ -363,7 +363,7 @@ impl Default for CoreTypePrinter {
// TODO: Remove this entirely, there is no "default", its view specific lets not make this some defined behavior.
let default_settings = crate::settings::Settings::new();
let name = default_settings.get_string("analysis.types.printerName");
- Self::printer_by_name(name).unwrap()
+ Self::printer_by_name(&name).unwrap()
}
}
diff --git a/rust/src/types.rs b/rust/src/types.rs
index 33972965..5a39eb27 100644
--- a/rust/src/types.rs
+++ b/rust/src/types.rs
@@ -258,7 +258,7 @@ impl TypeBuilder {
}
}
- pub fn named_int<S: IntoCStr>(width: usize, is_signed: bool, alt_name: S) -> Self {
+ pub fn named_int(width: usize, is_signed: bool, alt_name: &str) -> Self {
let mut is_signed = Conf::new(is_signed, MAX_CONFIDENCE).into();
// let alt_name = BnString::new(alt_name);
let alt_name = alt_name.to_cstr(); // This segfaulted once, so the above version is there if we need to change to it, but in theory this is copied into a `const string&` on the C++ side; I'm just not 100% confident that a constant reference copies data
@@ -273,24 +273,12 @@ impl TypeBuilder {
}
pub fn float(width: usize) -> Self {
- unsafe {
- Self::from_raw(BNCreateFloatTypeBuilder(
- width,
- BnString::new("").as_ptr() as *mut _,
- ))
- }
+ unsafe { Self::from_raw(BNCreateFloatTypeBuilder(width, c"".as_ptr())) }
}
- pub fn named_float<S: IntoCStr>(width: usize, alt_name: S) -> Self {
- // let alt_name = BnString::new(alt_name);
- let alt_name = alt_name.to_cstr(); // See same line in `named_int` above
-
- unsafe {
- Self::from_raw(BNCreateFloatTypeBuilder(
- width,
- alt_name.as_ref().as_ptr() as _,
- ))
- }
+ pub fn named_float(width: usize, alt_name: &str) -> Self {
+ let alt_name = alt_name.to_cstr();
+ unsafe { Self::from_raw(BNCreateFloatTypeBuilder(width, alt_name.as_ptr())) }
}
pub fn array<'a, T: Into<Conf<&'a Type>>>(ty: T, count: u64) -> Self {
@@ -630,53 +618,34 @@ impl Type {
}
pub fn wide_char(width: usize) -> Ref<Self> {
- unsafe {
- Self::ref_from_raw(BNCreateWideCharType(
- width,
- BnString::new("").as_ptr() as *mut _,
- ))
- }
+ unsafe { Self::ref_from_raw(BNCreateWideCharType(width, c"".as_ptr())) }
}
pub fn int(width: usize, is_signed: bool) -> Ref<Self> {
let mut is_signed = Conf::new(is_signed, MAX_CONFIDENCE).into();
- unsafe {
- Self::ref_from_raw(BNCreateIntegerType(
- width,
- &mut is_signed,
- BnString::new("").as_ptr() as *mut _,
- ))
- }
+ unsafe { Self::ref_from_raw(BNCreateIntegerType(width, &mut is_signed, c"".as_ptr())) }
}
- pub fn named_int<S: IntoCStr>(width: usize, is_signed: bool, alt_name: S) -> Ref<Self> {
+ pub fn named_int(width: usize, is_signed: bool, alt_name: &str) -> Ref<Self> {
let mut is_signed = Conf::new(is_signed, MAX_CONFIDENCE).into();
- // let alt_name = BnString::new(alt_name);
- let alt_name = alt_name.to_cstr(); // This segfaulted once, so the above version is there if we need to change to it, but in theory this is copied into a `const string&` on the C++ side; I'm just not 100% confident that a constant reference copies data
+ let alt_name = alt_name.to_cstr();
unsafe {
Self::ref_from_raw(BNCreateIntegerType(
width,
&mut is_signed,
- alt_name.as_ref().as_ptr() as _,
+ alt_name.as_ptr(),
))
}
}
pub fn float(width: usize) -> Ref<Self> {
- unsafe {
- Self::ref_from_raw(BNCreateFloatType(
- width,
- BnString::new("").as_ptr() as *mut _,
- ))
- }
+ unsafe { Self::ref_from_raw(BNCreateFloatType(width, c"".as_ptr())) }
}
- pub fn named_float<S: IntoCStr>(width: usize, alt_name: S) -> Ref<Self> {
- // let alt_name = BnString::new(alt_name);
- let alt_name = alt_name.to_cstr(); // See same line in `named_int` above
-
- unsafe { Self::ref_from_raw(BNCreateFloatType(width, alt_name.as_ref().as_ptr() as _)) }
+ pub fn named_float(width: usize, alt_name: &str) -> Ref<Self> {
+ let alt_name = alt_name.to_cstr();
+ unsafe { Self::ref_from_raw(BNCreateFloatType(width, alt_name.as_ptr())) }
}
pub fn array<'a, T: Into<Conf<&'a Type>>>(ty: T, count: u64) -> Ref<Self> {
@@ -1217,7 +1186,7 @@ impl EnumerationBuilder {
unsafe { Enumeration::ref_from_raw(BNFinalizeEnumerationBuilder(self.handle)) }
}
- pub fn append<S: IntoCStr>(&mut self, name: S) -> &mut Self {
+ pub fn append(&mut self, name: &str) -> &mut Self {
let name = name.to_cstr();
unsafe {
BNAddEnumerationBuilderMember(self.handle, name.as_ref().as_ptr() as _);
@@ -1225,7 +1194,7 @@ impl EnumerationBuilder {
self
}
- pub fn insert<S: IntoCStr>(&mut self, name: S, value: u64) -> &mut Self {
+ pub fn insert(&mut self, name: &str, value: u64) -> &mut Self {
let name = name.to_cstr();
unsafe {
BNAddEnumerationBuilderMemberWithValue(self.handle, name.as_ref().as_ptr() as _, value);
@@ -1233,7 +1202,7 @@ impl EnumerationBuilder {
self
}
- pub fn replace<S: IntoCStr>(&mut self, id: usize, name: S, value: u64) -> &mut Self {
+ pub fn replace(&mut self, id: usize, name: &str, value: u64) -> &mut Self {
let name = name.to_cstr();
unsafe {
BNReplaceEnumerationBuilderMember(self.handle, id, name.as_ref().as_ptr() as _, value);
@@ -1476,10 +1445,10 @@ impl StructureBuilder {
self
}
- pub fn append<'a, S: IntoCStr, T: Into<Conf<&'a Type>>>(
+ pub fn append<'a, T: Into<Conf<&'a Type>>>(
&mut self,
ty: T,
- name: S,
+ name: &str,
access: MemberAccess,
scope: MemberScope,
) -> &mut Self {
@@ -1504,7 +1473,7 @@ impl StructureBuilder {
) -> &mut Self {
self.insert(
&member.ty,
- member.name,
+ &member.name,
member.offset,
overwrite_existing,
member.access,
@@ -1513,10 +1482,10 @@ impl StructureBuilder {
self
}
- pub fn insert<'a, S: IntoCStr, T: Into<Conf<&'a Type>>>(
+ pub fn insert<'a, T: Into<Conf<&'a Type>>>(
&mut self,
ty: T,
- name: S,
+ name: &str,
offset: u64,
overwrite_existing: bool,
access: MemberAccess,
@@ -1538,11 +1507,11 @@ impl StructureBuilder {
self
}
- pub fn replace<'a, S: IntoCStr, T: Into<Conf<&'a Type>>>(
+ pub fn replace<'a, T: Into<Conf<&'a Type>>>(
&mut self,
index: usize,
ty: T,
- name: S,
+ name: &str,
overwrite_existing: bool,
) -> &mut Self {
let name = name.to_cstr();
@@ -1870,9 +1839,9 @@ impl NamedTypeReference {
/// You should not assign type ids yourself: if you use this to reference a type you are going
/// to create but have not yet created, you may run into problems when giving your types to
/// a BinaryView.
- pub fn new_with_id<T: Into<QualifiedName>, S: IntoCStr>(
+ pub fn new_with_id<T: Into<QualifiedName>>(
type_class: NamedTypeReferenceClass,
- type_id: S,
+ type_id: &str,
name: T,
) -> Ref<Self> {
let type_id = type_id.to_cstr();
@@ -1902,7 +1871,7 @@ impl NamedTypeReference {
}
fn target_helper(&self, bv: &BinaryView, visited: &mut HashSet<String>) -> Option<Ref<Type>> {
- let ty = bv.type_by_id(self.id())?;
+ let ty = bv.type_by_id(&self.id())?;
match ty.type_class() {
TypeClass::NamedTypeReferenceClass => {
// Recurse into the NTR type until we get the target type.
diff --git a/rust/src/websocket/client.rs b/rust/src/websocket/client.rs
index aa69c381..fc56dc0b 100644
--- a/rust/src/websocket/client.rs
+++ b/rust/src/websocket/client.rs
@@ -18,11 +18,9 @@ pub trait WebsocketClient: Sync + Send {
/// Called to construct this client object with the given core object.
fn from_core(core: Ref<CoreWebsocketClient>) -> Self;
- fn connect<I, K, V>(&self, host: &str, headers: I) -> bool
+ fn connect<I>(&self, host: &str, headers: I) -> bool
where
- I: IntoIterator<Item = (K, V)>,
- K: IntoCStr,
- V: IntoCStr;
+ I: IntoIterator<Item = (String, String)>;
fn write(&self, data: &[u8]) -> bool;
@@ -69,20 +67,13 @@ impl CoreWebsocketClient {
/// * `host` - Full url with scheme, domain, optionally port, and path
/// * `headers` - HTTP header keys and values
/// * `callback` - Callbacks for various websocket events
- pub fn initialize_connection<I, K, V, C>(
- &self,
- host: &str,
- headers: I,
- callbacks: &mut C,
- ) -> bool
+ pub fn initialize_connection<I, C>(&self, host: &str, headers: I, callbacks: &mut C) -> bool
where
- I: IntoIterator<Item = (K, V)>,
- K: IntoCStr,
- V: IntoCStr,
+ I: IntoIterator<Item = (String, String)>,
C: WebsocketClientCallback,
{
let url = host.to_cstr();
- let (header_keys, header_values): (Vec<K::Result>, Vec<V::Result>) = headers
+ let (header_keys, header_values): (Vec<_>, Vec<_>) = headers
.into_iter()
.map(|(k, v)| (k.to_cstr(), v.to_cstr()))
.unzip();
@@ -187,8 +178,10 @@ pub(crate) unsafe extern "C" fn cb_connect<W: WebsocketClient>(
let header_count = usize::try_from(header_count).unwrap();
let header_keys = core::slice::from_raw_parts(header_keys as *const BnString, header_count);
let header_values = core::slice::from_raw_parts(header_values as *const BnString, header_count);
- let header_keys_str = header_keys.iter().map(|s| s.to_string_lossy());
- let header_values_str = header_values.iter().map(|s| s.to_string_lossy());
+ let header_keys_str = header_keys.iter().map(|s| s.to_string_lossy().to_string());
+ let header_values_str = header_values
+ .iter()
+ .map(|s| s.to_string_lossy().to_string());
let header = header_keys_str.zip(header_values_str);
ctxt.connect(&host.to_string_lossy(), header)
}
diff --git a/rust/src/websocket/provider.rs b/rust/src/websocket/provider.rs
index 40235c2b..914a3f16 100644
--- a/rust/src/websocket/provider.rs
+++ b/rust/src/websocket/provider.rs
@@ -80,7 +80,7 @@ impl CoreWebsocketProvider {
unsafe { Array::new(result, count, ()) }
}
- pub fn by_name<S: IntoCStr>(name: S) -> Option<CoreWebsocketProvider> {
+ pub fn by_name(name: &str) -> Option<CoreWebsocketProvider> {
let name = name.to_cstr();
let result = unsafe { BNGetWebsocketProviderByName(name.as_ptr()) };
NonNull::new(result).map(|h| unsafe { Self::from_raw(h) })
diff --git a/rust/src/worker_thread.rs b/rust/src/worker_thread.rs
index 8fbfb8ef..113a7d0b 100644
--- a/rust/src/worker_thread.rs
+++ b/rust/src/worker_thread.rs
@@ -17,7 +17,7 @@ impl WorkerThreadActionExecutor {
}
}
-pub fn execute_on_worker_thread<F: Fn() + 'static, S: IntoCStr>(name: S, f: F) {
+pub fn execute_on_worker_thread<F: Fn() + 'static>(name: &str, f: F) {
let boxed_executor = Box::new(WorkerThreadActionExecutor { func: Box::new(f) });
let raw_executor = Box::into_raw(boxed_executor);
let name = name.to_cstr();
@@ -30,7 +30,7 @@ pub fn execute_on_worker_thread<F: Fn() + 'static, S: IntoCStr>(name: S, f: F) {
}
}
-pub fn execute_on_worker_thread_priority<F: Fn() + 'static, S: IntoCStr>(name: S, f: F) {
+pub fn execute_on_worker_thread_priority<F: Fn() + 'static>(name: &str, f: F) {
let boxed_executor = Box::new(WorkerThreadActionExecutor { func: Box::new(f) });
let raw_executor = Box::into_raw(boxed_executor);
let name = name.to_cstr();
@@ -43,7 +43,7 @@ pub fn execute_on_worker_thread_priority<F: Fn() + 'static, S: IntoCStr>(name: S
}
}
-pub fn execute_on_worker_thread_interactive<F: Fn() + 'static, S: IntoCStr>(name: S, f: F) {
+pub fn execute_on_worker_thread_interactive<F: Fn() + 'static>(name: &str, f: F) {
let boxed_executor = Box::new(WorkerThreadActionExecutor { func: Box::new(f) });
let raw_executor = Box::into_raw(boxed_executor);
let name = name.to_cstr();
diff --git a/rust/src/workflow.rs b/rust/src/workflow.rs
index 5b908ddd..0b1925a9 100644
--- a/rust/src/workflow.rs
+++ b/rust/src/workflow.rs
@@ -108,7 +108,7 @@ impl AnalysisContext {
}
}
- pub fn inform<S: IntoCStr>(&self, request: S) -> bool {
+ pub fn inform(&self, request: &str) -> bool {
let request = request.to_cstr();
unsafe { BNAnalysisContextInform(self.handle.as_ptr(), request.as_ptr()) }
}
@@ -161,7 +161,7 @@ impl Activity {
Ref::new(Self { handle })
}
- pub fn new<S: IntoCStr>(config: S) -> Ref<Self> {
+ pub fn new(config: &str) -> Ref<Self> {
unsafe extern "C" fn cb_action_nop(_: *mut c_void, _: *mut BNAnalysisContext) {}
let config = config.to_cstr();
let result =
@@ -169,9 +169,8 @@ impl Activity {
unsafe { Activity::ref_from_raw(NonNull::new(result).unwrap()) }
}
- pub fn new_with_action<S, F>(config: S, mut action: F) -> Ref<Self>
+ pub fn new_with_action<F>(config: &str, mut action: F) -> Ref<Self>
where
- S: IntoCStr,
F: FnMut(&AnalysisContext),
{
unsafe extern "C" fn cb_action<F: FnMut(&AnalysisContext)>(
@@ -240,7 +239,7 @@ impl Workflow {
/// Create a new unregistered [Workflow] with no activities.
///
/// To get a copy of an existing registered [Workflow] use [Workflow::clone_to].
- pub fn new<S: IntoCStr>(name: S) -> Ref<Self> {
+ pub fn new(name: &str) -> Ref<Self> {
let name = name.to_cstr();
let result = unsafe { BNCreateWorkflow(name.as_ptr()) };
unsafe { Workflow::ref_from_raw(NonNull::new(result).unwrap()) }
@@ -250,7 +249,7 @@ impl Workflow {
///
/// * `name` - the name for the new [Workflow]
#[must_use]
- pub fn clone_to<S: IntoCStr + Clone>(&self, name: S) -> Ref<Workflow> {
+ pub fn clone_to(&self, name: &str) -> Ref<Workflow> {
self.clone_to_with_root(name, "")
}
@@ -259,11 +258,7 @@ impl Workflow {
/// * `name` - the name for the new [Workflow]
/// * `root_activity` - perform the clone operation with this activity as the root
#[must_use]
- pub fn clone_to_with_root<S: IntoCStr, A: IntoCStr>(
- &self,
- name: S,
- root_activity: A,
- ) -> Ref<Workflow> {
+ pub fn clone_to_with_root(&self, name: &str, root_activity: &str) -> Ref<Workflow> {
let raw_name = name.to_cstr();
let activity = root_activity.to_cstr();
unsafe {
@@ -278,7 +273,7 @@ impl Workflow {
}
}
- pub fn instance<S: IntoCStr>(name: S) -> Ref<Workflow> {
+ pub fn instance(name: &str) -> Ref<Workflow> {
let name = name.to_cstr();
let result = unsafe { BNWorkflowInstance(name.as_ptr()) };
unsafe { Workflow::ref_from_raw(NonNull::new(result).unwrap()) }
@@ -306,7 +301,7 @@ impl Workflow {
/// Register this [Workflow], making it immutable and available for use.
///
/// * `configuration` - a JSON representation of the workflow configuration
- pub fn register_with_config<S: IntoCStr>(&self, config: S) -> Result<(), ()> {
+ pub fn register_with_config(&self, config: &str) -> Result<(), ()> {
let config = config.to_cstr();
if unsafe { BNRegisterWorkflow(self.handle.as_ptr(), config.as_ptr()) } {
Ok(())
@@ -351,7 +346,7 @@ impl Workflow {
}
/// Determine if an Activity exists in this [Workflow].
- pub fn contains<A: IntoCStr>(&self, activity: A) -> bool {
+ pub fn contains(&self, activity: &str) -> bool {
let activity = activity.to_cstr();
unsafe { BNWorkflowContains(self.handle.as_ptr(), activity.as_ptr()) }
}
@@ -365,7 +360,7 @@ impl Workflow {
/// [Workflow], just for the given `activity`.
///
/// `activity` - return the configuration for the `activity`
- pub fn configuration_with_activity<A: IntoCStr>(&self, activity: A) -> String {
+ pub fn configuration_with_activity(&self, activity: &str) -> String {
let activity = activity.to_cstr();
let result = unsafe { BNWorkflowGetConfiguration(self.handle.as_ptr(), activity.as_ptr()) };
assert!(!result.is_null());
@@ -382,7 +377,7 @@ impl Workflow {
}
/// Retrieve the Activity object for the specified `name`.
- pub fn activity<A: IntoCStr>(&self, name: A) -> Option<Ref<Activity>> {
+ pub fn activity(&self, name: &str) -> Option<Ref<Activity>> {
let name = name.to_cstr();
let result = unsafe { BNWorkflowGetActivity(self.handle.as_ptr(), name.as_ptr()) };
NonNull::new(result).map(|a| unsafe { Activity::ref_from_raw(a) })
@@ -392,7 +387,7 @@ impl Workflow {
/// specified just for the given `activity`.
///
/// * `activity` - if specified, return the roots for the `activity`
- pub fn activity_roots<A: IntoCStr>(&self, activity: A) -> Array<BnString> {
+ pub fn activity_roots(&self, activity: &str) -> Array<BnString> {
let activity = activity.to_cstr();
let mut count = 0;
let result = unsafe {
@@ -406,7 +401,7 @@ impl Workflow {
///
/// * `activity` - if specified, return the direct children and optionally the descendants of the `activity` (includes `activity`)
/// * `immediate` - whether to include only direct children of `activity` or all descendants
- pub fn subactivities<A: IntoCStr>(&self, activity: A, immediate: bool) -> Array<BnString> {
+ pub fn subactivities(&self, activity: &str, immediate: bool) -> Array<BnString> {
let activity = activity.to_cstr();
let mut count = 0;
let result = unsafe {
@@ -425,9 +420,8 @@ impl Workflow {
///
/// * `activity` - the Activity node to assign children
/// * `activities` - the list of Activities to assign
- pub fn assign_subactivities<A, I>(&self, activity: A, activities: I) -> bool
+ pub fn assign_subactivities<I>(&self, activity: &str, activities: I) -> bool
where
- A: IntoCStr,
I: IntoIterator,
I::Item: IntoCStr,
{
@@ -453,9 +447,8 @@ impl Workflow {
///
/// * `activity` - the Activity node for which to insert `activities` before
/// * `activities` - the list of Activities to insert
- pub fn insert<A, I>(&self, activity: A, activities: I) -> bool
+ pub fn insert<I>(&self, activity: &str, activities: I) -> bool
where
- A: IntoCStr,
I: IntoIterator,
I::Item: IntoCStr,
{
@@ -476,9 +469,8 @@ impl Workflow {
///
/// * `activity` - the Activity node for which to insert `activities` after
/// * `activities` - the list of Activities to insert
- pub fn insert_after<A, I>(&self, activity: A, activities: I) -> bool
+ pub fn insert_after<I>(&self, activity: &str, activities: I) -> bool
where
- A: IntoCStr,
I: IntoIterator,
I::Item: IntoCStr,
{
@@ -496,7 +488,7 @@ impl Workflow {
}
/// Remove the specified `activity`
- pub fn remove<A: IntoCStr>(&self, activity: A) -> bool {
+ pub fn remove(&self, activity: &str) -> bool {
let activity = activity.to_cstr();
unsafe { BNWorkflowRemove(self.handle.as_ptr(), activity.as_ptr()) }
}
@@ -505,7 +497,7 @@ impl Workflow {
///
/// * `activity` - the Activity to replace
/// * `new_activity` - the replacement Activity
- pub fn replace<A: IntoCStr, N: IntoCStr>(&self, activity: A, new_activity: N) -> bool {
+ pub fn replace(&self, activity: &str, new_activity: &str) -> bool {
let activity = activity.to_cstr();
let new_activity = new_activity.to_cstr();
unsafe {
@@ -521,11 +513,7 @@ impl Workflow {
///
/// * `activity` - if specified, generate the Flowgraph using `activity` as the root
/// * `sequential` - whether to generate a **Composite** or **Sequential** style graph
- pub fn graph<A: IntoCStr>(
- &self,
- activity: A,
- sequential: Option<bool>,
- ) -> Option<Ref<FlowGraph>> {
+ pub fn graph(&self, activity: &str, sequential: Option<bool>) -> Option<Ref<FlowGraph>> {
let sequential = sequential.unwrap_or(false);
let activity = activity.to_cstr();
let graph =