pub struct CapeValueIn<'a> {
interface: &'a *mut ICapeValue,
}Expand description
CapeValueIn wraps a reference to an ICapeValue interface pointer.
Given a reference to an ICapeValue interface pointer, this allows getting, but not setting, the value.
This interface is typically used as arguments to rust methods on traits that are generated from CAPE-OPEN interfaces that have ICapeValue input arguments.
This class takes a reference to the interface pointer.
A NULL pointer is treated as an empty value.
§Examples
use cobia::*;
fn test_content(v: &CapeValueIn) {
assert_eq!(v.get_string().unwrap(), "my value".to_string());
}
let val = cobia::CapeValueImpl::from_string("my value".into());
test_content(&CapeValueInFromProvider::from(&val).as_cape_value_in())Fields§
§interface: &'a *mut ICapeValueImplementations§
Source§impl<'a> CapeValueIn<'a>
impl<'a> CapeValueIn<'a>
Sourcepub fn new(interface: &'a *mut ICapeValue) -> Self
pub fn new(interface: &'a *mut ICapeValue) -> Self
Create v new CapeValueIn from an ICapeValue interface pointer.
§Arguments
interface- A pointer to an ICapeValue interface
§Examples
use cobia::*;
use cobia::prelude::*;
let val = cobia::CapeValueImpl::from_integer(-8);
let i_cape_value=val.as_cape_value_in();
let mut i_cape_value_ptr=(&i_cape_value as *const C::ICapeValue).cast_mut(); //normally a pointer to the interface is received
let v = cobia::CapeValueIn::new(&mut i_cape_value_ptr); //CapeValueIn from *mut C::ICapeValue
assert_eq!(v.get_integer().unwrap(), -8);Sourcepub fn get_type(&self) -> Result<CapeValueType, COBIAError>
pub fn get_type(&self) -> Result<CapeValueType, COBIAError>
Get the value type
§Examples
use cobia::*;
fn test_type(v: &CapeValueIn) {
assert_eq!(v.get_type().unwrap(), cobia::CapeValueType::String);
}
let val = cobia::CapeValueImpl::from_string("hydrogen".to_string());
test_type(&CapeValueInFromProvider::from(&val).as_cape_value_in())Sourcepub fn get_string(&self) -> Result<String, COBIAError>
pub fn get_string(&self) -> Result<String, COBIAError>
Get the value as a string
Get the value as a string. If the value is not a string, an error is returned.
§Examples
use cobia::*;
fn test_string(v: &CapeValueIn) {
assert_eq!(v.get_string().unwrap(), "hydrogen".to_string());
}
let val = cobia::CapeValueImpl::from_string("hydrogen".to_string());
test_string(&CapeValueInFromProvider::from(&val).as_cape_value_in())Sourcepub fn get_integer(&self) -> Result<i32, COBIAError>
pub fn get_integer(&self) -> Result<i32, COBIAError>
Get the value as an integer
Get the value as an integer. If the value is not an integer, an error is returned.
§Examples
use cobia::*;
fn test_integer(v: &CapeValueIn) {
assert_eq!(v.get_integer().unwrap(), 8);
}
let val = cobia::CapeValueImpl::from_integer(8);
test_integer(&CapeValueInFromProvider::from(&val).as_cape_value_in())Sourcepub fn get_boolean(&self) -> Result<bool, COBIAError>
pub fn get_boolean(&self) -> Result<bool, COBIAError>
Get the value as a boolean
Get the value as a boolean. If the value is not a boolean, an error is returned.
§Examples
use cobia::*;
fn test_boolean(v: &CapeValueIn) {
assert_eq!(v.get_boolean().unwrap(), true);
}
let val = cobia::CapeValueImpl::from_boolean(true);
test_boolean(&CapeValueInFromProvider::from(&val).as_cape_value_in())Sourcepub fn get_real(&self) -> Result<f64, COBIAError>
pub fn get_real(&self) -> Result<f64, COBIAError>
Get the value as a real
Get the value as a real. If the value is not a real, an error is returned.
§Examples
use cobia::*;
fn test_real(v: &CapeValueIn) {
assert_eq!(v.get_real().unwrap(), 2.01568);
}
let val = cobia::CapeValueImpl::from_real(2.01568);
test_real(&CapeValueInFromProvider::from(&val).as_cape_value_in())Trait Implementations§
Source§impl<'a> CapeValueProviderIn for CapeValueIn<'a>
impl<'a> CapeValueProviderIn for CapeValueIn<'a>
Source§fn as_cape_value_in(&self) -> ICapeValue
fn as_cape_value_in(&self) -> ICapeValue
Source§impl<'a> Display for CapeValueIn<'a>
impl<'a> Display for CapeValueIn<'a>
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Display the content of the value
§Examples
use cobia::*;
fn test_format(v: &CapeValueIn) {
assert_eq!(format!("{}", v), "\"1333-74-0\"");
}
let val = cobia::CapeValueImpl::from_string("1333-74-0".into());
test_format(&CapeValueInFromProvider::from(&val).as_cape_value_in())