From 9dadf92c16da5cd21def79ae39ca98803c9208ec Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Mon, 5 May 2025 13:17:30 -0400 Subject: [Rust] Rename `AsCStr` to `IntoCStr` --- rust/src/settings.rs | 82 +++++++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 39 deletions(-) (limited to 'rust/src/settings.rs') diff --git a/rust/src/settings.rs b/rust/src/settings.rs index be2fd955..35f7b7a0 100644 --- a/rust/src/settings.rs +++ b/rust/src/settings.rs @@ -20,7 +20,7 @@ use std::fmt::Debug; use crate::binary_view::BinaryView; use crate::rc::*; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; use crate::function::Function; @@ -44,7 +44,7 @@ impl Settings { Self::new_with_id(GLOBAL_INSTANCE_ID) } - pub fn new_with_id(instance_id: S) -> Ref { + pub fn new_with_id(instance_id: S) -> Ref { 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(&self, resource_id: S) { + pub fn set_resource_id(&self, resource_id: S) { let resource_id = resource_id.to_cstr(); unsafe { BNSettingsSetResourceId(self.handle, resource_id.as_ptr()) }; } @@ -62,11 +62,11 @@ impl Settings { unsafe { BnString::into_string(BNSettingsSerializeSchema(self.handle)) } } - pub fn deserialize_schema(&self, schema: S) -> bool { + pub fn deserialize_schema(&self, schema: S) -> bool { self.deserialize_schema_with_scope(schema, SettingsScope::SettingsAutoScope) } - pub fn deserialize_schema_with_scope( + pub fn deserialize_schema_with_scope( &self, schema: S, scope: SettingsScope, @@ -75,7 +75,7 @@ impl Settings { unsafe { BNSettingsDeserializeSchema(self.handle, schema.as_ptr(), scope, true) } } - pub fn contains(&self, key: S) -> bool { + pub fn contains(&self, key: S) -> bool { let key = key.to_cstr(); unsafe { BNSettingsContains(self.handle, key.as_ptr()) } @@ -90,11 +90,11 @@ impl Settings { // TODO Update the settings API to take an optional BinaryView or Function. Separate functions or...? - pub fn get_bool(&self, key: S) -> bool { + pub fn get_bool(&self, key: S) -> bool { self.get_bool_with_opts(key, &mut QueryOptions::default()) } - pub fn get_bool_with_opts(&self, key: S, options: &mut QueryOptions) -> bool { + pub fn get_bool_with_opts(&self, key: S, options: &mut QueryOptions) -> bool { let key = key.to_cstr(); let view_ptr = match options.view.as_ref() { Some(view) => view.handle, @@ -115,11 +115,11 @@ impl Settings { } } - pub fn get_double(&self, key: S) -> f64 { + pub fn get_double(&self, key: S) -> f64 { self.get_double_with_opts(key, &mut QueryOptions::default()) } - pub fn get_double_with_opts(&self, key: S, options: &mut QueryOptions) -> f64 { + pub fn get_double_with_opts(&self, key: S, options: &mut QueryOptions) -> f64 { let key = key.to_cstr(); let view_ptr = match options.view.as_ref() { Some(view) => view.handle, @@ -140,11 +140,11 @@ impl Settings { } } - pub fn get_integer(&self, key: S) -> u64 { + pub fn get_integer(&self, key: S) -> u64 { self.get_integer_with_opts(key, &mut QueryOptions::default()) } - pub fn get_integer_with_opts(&self, key: S, options: &mut QueryOptions) -> u64 { + pub fn get_integer_with_opts(&self, key: S, options: &mut QueryOptions) -> u64 { let key = key.to_cstr(); let view_ptr = match options.view.as_ref() { Some(view) => view.handle, @@ -165,11 +165,11 @@ impl Settings { } } - pub fn get_string(&self, key: S) -> String { + pub fn get_string(&self, key: S) -> String { self.get_string_with_opts(key, &mut QueryOptions::default()) } - pub fn get_string_with_opts(&self, key: S, options: &mut QueryOptions) -> String { + pub fn get_string_with_opts(&self, key: S, options: &mut QueryOptions) -> String { let key = key.to_cstr(); let view_ptr = match options.view.as_ref() { Some(view) => view.handle, @@ -190,11 +190,11 @@ impl Settings { } } - pub fn get_string_list(&self, key: S) -> Array { + pub fn get_string_list(&self, key: S) -> Array { self.get_string_list_with_opts(key, &mut QueryOptions::default()) } - pub fn get_string_list_with_opts( + pub fn get_string_list_with_opts( &self, key: S, options: &mut QueryOptions, @@ -225,11 +225,11 @@ impl Settings { } } - pub fn get_json(&self, key: S) -> String { + pub fn get_json(&self, key: S) -> String { self.get_json_with_opts(key, &mut QueryOptions::default()) } - pub fn get_json_with_opts(&self, key: S, options: &mut QueryOptions) -> String { + pub fn get_json_with_opts(&self, key: S, options: &mut QueryOptions) -> String { let key = key.to_cstr(); let view_ptr = match options.view.as_ref() { Some(view) => view.handle, @@ -250,11 +250,11 @@ impl Settings { } } - pub fn set_bool(&self, key: S, value: bool) { + pub fn set_bool(&self, key: S, value: bool) { self.set_bool_with_opts(key, value, &QueryOptions::default()) } - pub fn set_bool_with_opts(&self, key: S, value: bool, options: &QueryOptions) { + pub fn set_bool_with_opts(&self, key: S, value: bool, options: &QueryOptions) { let key = key.to_cstr(); let view_ptr = match options.view.as_ref() { Some(view) => view.handle, @@ -276,10 +276,10 @@ impl Settings { } } - pub fn set_double(&self, key: S, value: f64) { + pub fn set_double(&self, key: S, value: f64) { self.set_double_with_opts(key, value, &QueryOptions::default()) } - pub fn set_double_with_opts(&self, key: S, value: f64, options: &QueryOptions) { + pub fn set_double_with_opts(&self, key: S, value: f64, options: &QueryOptions) { let key = key.to_cstr(); let view_ptr = match options.view.as_ref() { Some(view) => view.handle, @@ -301,11 +301,11 @@ impl Settings { } } - pub fn set_integer(&self, key: S, value: u64) { + pub fn set_integer(&self, key: S, value: u64) { self.set_integer_with_opts(key, value, &QueryOptions::default()) } - pub fn set_integer_with_opts(&self, key: S, value: u64, options: &QueryOptions) { + pub fn set_integer_with_opts(&self, key: S, value: u64, options: &QueryOptions) { let key = key.to_cstr(); let view_ptr = match options.view.as_ref() { Some(view) => view.handle, @@ -327,11 +327,11 @@ impl Settings { } } - pub fn set_string(&self, key: S1, value: S2) { + pub fn set_string(&self, key: S1, value: S2) { self.set_string_with_opts(key, value, &QueryOptions::default()) } - pub fn set_string_with_opts( + pub fn set_string_with_opts( &self, key: S1, value: S2, @@ -359,7 +359,7 @@ impl Settings { } } - pub fn set_string_list>( + pub fn set_string_list>( &self, key: S1, value: I, @@ -367,7 +367,7 @@ impl Settings { self.set_string_list_with_opts(key, value, &QueryOptions::default()) } - pub fn set_string_list_with_opts>( + pub fn set_string_list_with_opts>( &self, key: S1, value: I, @@ -398,11 +398,11 @@ impl Settings { } } - pub fn set_json(&self, key: S1, value: S2) -> bool { + pub fn set_json(&self, key: S1, value: S2) -> bool { self.set_json_with_opts(key, value, &QueryOptions::default()) } - pub fn set_json_with_opts( + pub fn set_json_with_opts( &self, key: S1, value: S2, @@ -430,7 +430,7 @@ impl Settings { } } - pub fn get_property_string(&self, key: S, property: S) -> String { + pub fn get_property_string(&self, key: S, property: S) -> String { let key = key.to_cstr(); let property = property.to_cstr(); unsafe { @@ -442,7 +442,7 @@ impl Settings { } } - pub fn get_property_string_list(&self, key: S, property: S) -> Array { + pub fn get_property_string_list(&self, key: S, property: S) -> Array { let key = key.to_cstr(); let property = property.to_cstr(); let mut size: usize = 0; @@ -460,7 +460,7 @@ impl Settings { } } - pub fn update_bool_property(&self, key: S, property: S, value: bool) { + pub fn update_bool_property(&self, key: S, property: S, value: bool) { let key = key.to_cstr(); let property = property.to_cstr(); unsafe { @@ -468,7 +468,7 @@ impl Settings { } } - pub fn update_integer_property(&self, key: S, property: S, value: u64) { + pub fn update_integer_property(&self, key: S, property: S, value: u64) { let key = key.to_cstr(); let property = property.to_cstr(); unsafe { @@ -476,7 +476,7 @@ impl Settings { } } - pub fn update_double_property(&self, key: S, property: S, value: f64) { + pub fn update_double_property(&self, key: S, property: S, value: f64) { let key = key.to_cstr(); let property = property.to_cstr(); unsafe { @@ -484,7 +484,7 @@ impl Settings { } } - pub fn update_string_property(&self, key: S, property: S, value: S) { + pub fn update_string_property(&self, key: S, property: S, value: S) { let key = key.to_cstr(); let property = property.to_cstr(); let value = value.to_cstr(); @@ -498,7 +498,7 @@ impl Settings { } } - pub fn update_string_list_property>( + pub fn update_string_list_property>( &self, key: S, property: S, @@ -520,14 +520,18 @@ impl Settings { } } - pub fn register_group(&self, group: S1, title: S2) -> bool { + pub fn register_group(&self, group: S1, title: S2) -> 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(&self, group: S1, properties: S2) -> bool { + pub fn register_setting_json( + &self, + group: S1, + properties: S2, + ) -> bool { let group = group.to_cstr(); let properties = properties.to_cstr(); -- cgit v1.3.1