pub struct CapeValueOut<'a> {
interface: &'a mut *mut ICapeValue,
}Expand description
CapeValueOut wraps an ICapeValue interface pointer.
Given a reference to an ICapeValue interface pointer, this allows setting and getting the value.
A reference to a NULL pointer is not allowed here.
This interface is typically used as arguments to rust methods on traits that are generated from CAPE-OPEN interfaces that have ICapeValue ouput arguments.
This class takes a mutable reference to the interface pointer, as it should be the only class that is in use at a time to change the data behind the interface (as the data pointer is cached)
§Examples
use cobia::*;
fn set_value(v: &mut CapeValueOut) {
v.set_string("my value").unwrap();
}
let mut val = cobia::CapeValueImpl::new();
set_value(&mut CapeValueOutFromProvider::from(&mut val).as_cape_value_out());
assert_eq!(val.value(), CapeValueContent::String("my value".into()));Fields§
§interface: &'a mut *mut ICapeValueImplementations§
Source§impl<'a> CapeValueOut<'a>
impl<'a> CapeValueOut<'a>
Sourcepub fn new(interface: &'a mut *mut ICapeValue) -> Self
pub fn new(interface: &'a mut *mut ICapeValue) -> Self
Create v new CapeValueOut from an ICapeValue interface pointer.
§Arguments
interface- A pointer to an ICapeValue interface
§Examples
use cobia::*;
use cobia::prelude::*;
let mut val = cobia::CapeValueImpl::from_integer(-8);
let i_cape_value=val.as_cape_value_out();
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::CapeValueOut::new(&mut i_cape_value_ptr); //CapeValueOut 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 check_type(v: &mut CapeValueOut) {
assert_eq!(v.get_type().unwrap(), cobia::CapeValueType::String);
}
let mut val = cobia::CapeValueImpl::from_string("hydrogen".into());
check_type(&mut CapeValueOutFromProvider::from(&mut val).as_cape_value_out());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 check_string(v: &mut CapeValueOut) {
assert_eq!(v.get_string().unwrap(), "hydrogen".to_string());
}
let mut val = cobia::CapeValueImpl::from_string("hydrogen".into());
check_string(&mut CapeValueOutFromProvider::from(&mut val).as_cape_value_out());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 check_integer(v: &mut CapeValueOut) {
assert_eq!(v.get_integer().unwrap(), 8);
}
let mut val = cobia::CapeValueImpl::from_integer(8);
check_integer(&mut CapeValueOutFromProvider::from(&mut val).as_cape_value_out());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 check_boolean(v: &mut CapeValueOut) {
assert_eq!(v.get_boolean().unwrap(), true);
}
let mut val = cobia::CapeValueImpl::from_boolean(true);
check_boolean(&mut CapeValueOutFromProvider::from(&mut val).as_cape_value_out());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 check_real(v: &mut CapeValueOut) {
assert_eq!(v.get_real().unwrap(), 2.01568);
}
let mut val = cobia::CapeValueImpl::from_real(2.01568);
check_real(&mut CapeValueOutFromProvider::from(&mut val).as_cape_value_out());Sourcepub fn set_string<T: AsRef<str>>(&self, value: T) -> Result<(), COBIAError>
pub fn set_string<T: AsRef<str>>(&self, value: T) -> Result<(), COBIAError>
Set the value as a string
§Arguments
value- The string value to set
§Examples
use cobia::*;
fn set_value(v: &mut CapeValueOut) {
v.set_string("my value").unwrap();
}
let mut val = cobia::CapeValueImpl::new();
set_value(&mut CapeValueOutFromProvider::from(&mut val).as_cape_value_out());
assert_eq!(val.value(), CapeValueContent::String("my value".into()));Sourcepub fn set_integer(&self, value: CapeInteger) -> Result<(), COBIAError>
pub fn set_integer(&self, value: CapeInteger) -> Result<(), COBIAError>
Set the value as an integer
§Arguments
value- The integer value to set
§Examples
use cobia::*;
fn set_value(v: &mut CapeValueOut) {
v.set_integer(8).unwrap();
}
let mut val = cobia::CapeValueImpl::new();
set_value(&mut CapeValueOutFromProvider::from(&mut val).as_cape_value_out());
assert_eq!(val.value(), CapeValueContent::Integer(8));Sourcepub fn set_boolean(&self, value: bool) -> Result<(), COBIAError>
pub fn set_boolean(&self, value: bool) -> Result<(), COBIAError>
Set the value as a boolean
§Arguments
value- The boolean value to set
§Examples
use cobia::*;
fn set_value(v: &mut CapeValueOut) {
v.set_boolean(true).unwrap()
}
let mut val = cobia::CapeValueImpl::new();
set_value(&mut CapeValueOutFromProvider::from(&mut val).as_cape_value_out());
assert_eq!(val.value(), CapeValueContent::Boolean(true));Sourcepub fn set_real(&self, value: CapeReal) -> Result<(), COBIAError>
pub fn set_real(&self, value: CapeReal) -> Result<(), COBIAError>
Set the value as a real
§Arguments
value- The real value to set
§Examples
use cobia::*;
fn set_value(v: &mut CapeValueOut) {
v.set_real(2.01568).unwrap();
}
let mut val = cobia::CapeValueImpl::new();
set_value(&mut CapeValueOutFromProvider::from(&mut val).as_cape_value_out());
assert_eq!(val.value(), cobia::cape_value_impl::CapeValueContent::Real(2.01568));Sourcepub fn set_empty(&self) -> Result<(), COBIAError>
pub fn set_empty(&self) -> Result<(), COBIAError>
Set the value to empty
Set the value to empty. This is equivalent to setting the value to None in rust.
§Examples
use cobia::*;
fn set_value(v: &mut CapeValueOut) {
v.set_empty().unwrap();
}
let mut val = cobia::CapeValueImpl::new();
set_value(&mut CapeValueOutFromProvider::from(&mut val).as_cape_value_out());
assert_eq!(val.value(), cobia::cape_value_impl::CapeValueContent::Empty);Sourcepub fn set<T: CapeValueProviderIn>(
&mut self,
value: &T,
) -> Result<(), COBIAError>
pub fn set<T: CapeValueProviderIn>( &mut self, value: &T, ) -> Result<(), COBIAError>
Set the value from a CapeValueProviderIn
Set the value from a CapeValueProviderIn. This allows setting the value from any type that implements the CapeValueProviderIn trait.
§Arguments
value- A reference to a type that implements the CapeValueProviderIn trait
§Examples
use cobia::*;
let mut val = cobia::CapeValueImpl::new();
let val1 = cobia::CapeValueImpl::from_string("hydrogen".into());
CapeValueOutFromProvider::from(&mut val).as_cape_value_out().set(&val1);
assert_eq!(val.value(), cobia::cape_value_impl::CapeValueContent::String("hydrogen".into()));Trait Implementations§
Source§impl<'a> CapeValueProviderOut for CapeValueOut<'a>
impl<'a> CapeValueProviderOut for CapeValueOut<'a>
Source§fn as_cape_value_out(&mut self) -> ICapeValue
fn as_cape_value_out(&mut self) -> ICapeValue
Source§impl<'a> Display for CapeValueOut<'a>
impl<'a> Display for CapeValueOut<'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: &mut CapeValueOut) {
assert_eq!(format!("{}", v), "\"1333-74-0\"");
}
let mut val = cobia::CapeValueImpl::from_string("1333-74-0".into());
test_format(&mut CapeValueOutFromProvider::from(&mut val).as_cape_value_out());