Struct CapeRegistryKeyWriter

Source
pub struct CapeRegistryKeyWriter<'a> {
    pub(crate) interface: *mut ICapeRegistryKeyWriter,
    pub(crate) writer: &'a CapeRegistryWriter,
}
Expand description

A writable COBIA registry key

This struct is used to write to a COBIA registry key. It is obtained from a CapeRegistryWriter and can be used to create subkeys and write values. It is valid only for the life span of the CapeRegistryWriter.

Values are not written to the registry until CapeRegistryWriter::commit() is called.

Fields§

§interface: *mut ICapeRegistryKeyWriter§writer: &'a CapeRegistryWriter

Implementations§

Source§

impl<'a> CapeRegistryKeyWriter<'a>

Source

pub fn create_sub_key( &self, writer: &'a CapeRegistryWriter, key_name: &str, ) -> Result<CapeRegistryKeyWriter<'_>, COBIAError>

Create a subkey

Create a subkey with the given name. The subkey is returned as a CapeRegistryKeyWriter. The subkey can be used to write values and create further subkeys. The subkey is not written to the registry until CapeRegistryWriter::commit() is called.

§Arguments
  • key_name - The name of the subkey to create
§Returns

A CapeRegistryKeyWriter for the new subkey

§Example
use cobia::*;
cobia::cape_open_initialize().unwrap();
{
  //create a key, then a sub key, and put a value in there
  let writer = CapeRegistryWriter::new(false).unwrap();
  let key=writer.create_key("/cobia_rust_create_sub_key").unwrap();
  let sub_key=key.create_sub_key(&writer,"sub_key").unwrap();
  sub_key.set_string_value("test_value", "test_value").unwrap();
  writer.commit().unwrap();
}
//read the value back
let reader = CapeRegistryKey::from_path("/cobia_rust_create_sub_key/sub_key").unwrap();
assert_eq!(reader.get_string_value("test_value",None).unwrap(), "test_value".to_string());
// now delete the entire key
let writer = CapeRegistryWriter::new(false).unwrap();
writer.delete_key("/cobia_rust_create_sub_key").unwrap();
writer.commit().unwrap();
//validate that it was deleted
let reader = CapeRegistryKey::from_path("/cobia_rust_create_sub_key");
assert!(reader.is_err());
cobia::cape_open_cleanup();
Source

pub fn delete_sub_key(&self, key_name: &str) -> Result<(), COBIAError>

Delete a subkey

Delete a subkey with the given name. The result is not written to the registry until CapeRegistryWriter::commit() is called.

§Arguments
  • key_name - The name of the subkey to delete
§Example
use cobia::*;
cobia::cape_open_initialize().unwrap();
{
  //create a key, then a sub key, and put a value in there
  let writer = CapeRegistryWriter::new(false).unwrap();
  let key=writer.create_key("/cobia_rust_delete_sub_key").unwrap();
  let sub_key=key.create_sub_key(&writer,"sub_key").unwrap();
  sub_key.set_string_value("test_value", "test_value").unwrap();
  writer.commit().unwrap();
}
//read the value back
let reader = CapeRegistryKey::from_path("/cobia_rust_delete_sub_key/sub_key").unwrap();
assert_eq!(reader.get_string_value("test_value",None).unwrap(), "test_value".to_string());
// now delete the sub key
let writer = CapeRegistryWriter::new(false).unwrap();
let key=writer.create_key("/cobia_rust_delete_sub_key").unwrap();
key.delete_sub_key("sub_key").unwrap();
writer.commit().unwrap();
//validate that it was deleted
let reader = CapeRegistryKey::from_path("/cobia_rust_delete_sub_key/sub_key");
assert!(reader.is_err());
// now delete the entire key
let writer = CapeRegistryWriter::new(false).unwrap();
writer.delete_key("/cobia_rust_delete_sub_key").unwrap();
writer.commit().unwrap();
//validate that it was deleted
let reader = CapeRegistryKey::from_path("/cobia_rust_delete_sub_key");
assert!(reader.is_err());
cobia::cape_open_cleanup();
Source

pub fn delete_value( &self, key_name: Option<&str>, value_name: &str, ) -> Result<(), COBIAError>

Delete a value

Delete a value with the given name. The result is not written to the registry until CapeRegistryWriter::commit() is called.

§Arguments
  • key_name - The name of the subkey to delete; if None, the current key is used
  • value_name - The name of the value to delete
§Example
use cobia::*;
cobia::cape_open_initialize().unwrap();
{
  //create a key, and put a value in there
  let writer = CapeRegistryWriter::new(false).unwrap();
  let key=writer.create_key("/cobia_rust_delete_value").unwrap();
  key.set_string_value("test_string_value", "I like COBIA").unwrap();
  writer.commit().unwrap();
}
//read the value back
let reader = CapeRegistryKey::from_path("/cobia_rust_delete_value").unwrap();
assert_eq!(reader.get_string_value("test_string_value",None).unwrap(), "I like COBIA".to_string());
// now delete the value
let writer = CapeRegistryWriter::new(false).unwrap();
let key=writer.create_key("/cobia_rust_delete_value").unwrap();
key.delete_value(None,"test_string_value").unwrap();
writer.commit().unwrap();
//validate that it was deleted
let reader = CapeRegistryKey::from_path("/cobia_rust_delete_value").unwrap();
let value = reader.get_string_value("test_string_value",None);
assert!(value.is_err());
// now delete the entire key
let writer = CapeRegistryWriter::new(false).unwrap();
writer.delete_key("/cobia_rust_delete_value").unwrap();
writer.commit().unwrap();
cobia::cape_open_cleanup();
Source

pub fn set_string_value<T1: AsRef<str>, T2: AsRef<str>>( &self, value_name: T1, value: T2, ) -> Result<(), COBIAError>

Write a string value

Write a string value with the given name. The result is not written to the registry until CapeRegistryWriter::commit() is called.

§Arguments
  • value_name - The name of the value to write
  • value - The value to write
§Example
use cobia::*;
cobia::cape_open_initialize().unwrap();
{
  //create a key, and put a value in there
  let writer = CapeRegistryWriter::new(false).unwrap();
  let key=writer.create_key("/cobia_rust_set_string_value").unwrap();
  key.set_string_value("another_string_value", "CAPE-OPEN is the defacto interop standard for chemical engineering software components").unwrap();
  writer.commit().unwrap();
}
//read the value back
let reader = CapeRegistryKey::from_path("/cobia_rust_set_string_value").unwrap();
assert_eq!(reader.get_string_value("another_string_value",None).unwrap(), "CAPE-OPEN is the defacto interop standard for chemical engineering software components".to_string());
// now delete the entire key
let writer = CapeRegistryWriter::new(false).unwrap();
writer.delete_key("/cobia_rust_set_string_value").unwrap();
writer.commit().unwrap();
cobia::cape_open_cleanup();
Source

pub fn put_integer_value( &self, value_name: &str, value: i32, ) -> Result<(), COBIAError>

Write an integer value

Write an integer value with the given name. The result is not written to the registry until CapeRegistryWriter::commit() is called.

§Arguments
  • value_name - The name of the value to write
  • value - The value to write
§Example
use cobia::*;
cobia::cape_open_initialize().unwrap();
{
  //create a key, and put a value in there
  let writer = CapeRegistryWriter::new(false).unwrap();
  let key=writer.create_key("/cobia_rust_put_integer_value").unwrap();
  key.put_integer_value("my_integer_value", 14).unwrap();
  writer.commit().unwrap();
}
//read the value back
assert_eq!(CapeRegistryKey::from_path("/cobia_rust_put_integer_value").unwrap().
	get_integer_value("my_integer_value",None).unwrap(), 14);
// now delete the entire key
let writer = CapeRegistryWriter::new(false).unwrap();
writer.delete_key("/cobia_rust_put_integer_value").unwrap();
writer.commit().unwrap();
cobia::cape_open_cleanup();
Source

pub fn put_uuid_value( &self, value_name: &str, value: &CapeUUID, ) -> Result<(), COBIAError>

Write an uuid value

Write an uuid value with the given name. The result is not written to the registry until CapeRegistryWriter::commit() is called.

§Arguments
  • value_name - The name of the value to write
  • value - The value to write
§Example
use cobia::*;
cobia::cape_open_initialize().unwrap();
let test_uuid = CapeUUID::new(); //generate unique uuid
{
  //create a key, and put a value in there
  let writer = CapeRegistryWriter::new(false).unwrap();
  let key=writer.create_key("/cobia_rust_put_uuid_value").unwrap();
  key.put_uuid_value("new_uuid", &test_uuid).unwrap();
  writer.commit().unwrap();
}
//read the value back
assert_eq!(CapeRegistryKey::from_path("/cobia_rust_put_uuid_value").unwrap().
	get_uuid_value("new_uuid",None).unwrap(), test_uuid);
// now delete the entire key
let writer = CapeRegistryWriter::new(false).unwrap();
writer.delete_key("/cobia_rust_put_uuid_value").unwrap();
writer.commit().unwrap();
cobia::cape_open_cleanup();
Source

pub fn put_empty_value(&self, value_name: &str) -> Result<(), COBIAError>

Write an empty value

Write an uuid value with the given name. The result is not written to the registry until CapeRegistryWriter::commit() is called.

Empty values are typically used to denote an option that is either set (value present) or not set (value not present).

§Arguments
  • value_name - The name of the value to write
§Example
use cobia::*;
cobia::cape_open_initialize().unwrap();
let test_uuid = CapeUUID::new(); //generate unique uuid
{
  //create a key, and put a value in there
  let writer = CapeRegistryWriter::new(false).unwrap();
  let key=writer.create_key("/cobia_rust_put_empty_value").unwrap();
  key.put_empty_value("test_empty_value").unwrap();
  writer.commit().unwrap();
}
//check existence and type
assert_eq!(CapeRegistryKey::from_path("/cobia_rust_put_empty_value").unwrap().
	get_value_type("test_empty_value",None).unwrap(), cobia::CapeRegistryValueType::Empty);
// now delete the entire key
let writer = CapeRegistryWriter::new(false).unwrap();
writer.delete_key("/cobia_rust_put_empty_value").unwrap();
writer.commit().unwrap();
cobia::cape_open_cleanup();

Trait Implementations§

Source§

impl<'a> CapeRegistryKeyReader for CapeRegistryKeyWriter<'a>

Source§

fn get_values(&self) -> Result<Vec<String>, COBIAError>

Get a list of all values names in the key Read more
Source§

fn get_keys(&self) -> Result<Vec<String>, COBIAError>

Get a list of all sub key names in the key Read more
Source§

fn get_value_type( &self, value_name: &str, sub_key: Option<&str>, ) -> Result<CapeRegistryValueType, COBIAError>

Get the type of a value Read more
Source§

fn get_string_value( &self, value_name: &str, sub_key: Option<&str>, ) -> Result<String, COBIAError>

Get a string value Read more
Source§

fn get_integer_value( &self, value_name: &str, sub_key: Option<&str>, ) -> Result<i32, COBIAError>

Get an integer value Read more
Source§

fn get_uuid_value( &self, value_name: &str, sub_key: Option<&str>, ) -> Result<CapeUUID, COBIAError>

Get a UUID value Read more
Source§

fn get_sub_key(&self, key_name: &str) -> Result<CapeRegistryKey, COBIAError>

Get a sub key Read more
Source§

fn is_all_users(&self, value_name: &str) -> Result<bool, COBIAError>

Check whether a particular value is in the registry for all users or just the current user Read more
Source§

impl<'a> CapeRegistryKeyReaderKey for CapeRegistryKeyWriter<'a>

Source§

impl<'a> Clone for CapeRegistryKeyWriter<'a>

Add pointer reference

ICapeRegistryKeyWriter derives from ICobiaBase, which contains addReference() and release(). The Clone trait calls addReference.

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Drop for CapeRegistryKeyWriter<'a>

Release pointer

ICapeRegistryKeyWriter derives from ICobiaBase, which contains addReference() and release(). The Drop trait calls release.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.