summaryrefslogtreecommitdiff
path: root/rust/src/database.rs
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-05-07 19:22:21 -0400
committerMason Reed <35282038+emesare@users.noreply.github.com>2025-05-12 17:45:24 -0400
commit2f214f6c9935e8ce8df4732cde44a540a003258c (patch)
tree6fe319433ef0d2ad75fcc58a50eaa632bb627ec9 /rust/src/database.rs
parentb4cf0be8816182c9efca037e27e9439482f8bf36 (diff)
[Rust] Reduce usage of `IntoCStr` in function signatures
This is being done to reduce complexity in function signatures, specifically many of the strings we are passing ultimately should be new types themselves instead of "just strings", things such as type ids. Another place which was confusing was dealing with filesystem related APIs, this commit turns most of those params into a stricter `Path` type. This is bringing the rust api more inline with both python and C++, where the wrapper eagerly converts the string into the languages standard string type. Special consideration must be made for symbols or other possible non utf-8 objects. This commit will be followed up with one that adds the `IntoCStr` bound on API's we want to keep as invalid utf-8 so we can for example, get section by name on a section with invalid utf-8.
Diffstat (limited to 'rust/src/database.rs')
-rw-r--r--rust/src/database.rs19
1 files changed, 9 insertions, 10 deletions
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()) }
}