Struct CapeValueOut

Source
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 ICapeValue

Implementations§

Source§

impl<'a> CapeValueOut<'a>

Source

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);
Source

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());
Source

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());
Source

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());
Source

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());
Source

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());
Source

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()));
Source

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));
Source

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));
Source

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));
Source

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);
Source

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>

Source§

fn as_cape_value_out(&mut self) -> ICapeValue

Convert to ICapeValue
Source§

impl<'a> Display for CapeValueOut<'a>

Source§

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());

Auto Trait Implementations§

§

impl<'a> Freeze for CapeValueOut<'a>

§

impl<'a> RefUnwindSafe for CapeValueOut<'a>

§

impl<'a> !Send for CapeValueOut<'a>

§

impl<'a> !Sync for CapeValueOut<'a>

§

impl<'a> Unpin for CapeValueOut<'a>

§

impl<'a> !UnwindSafe for CapeValueOut<'a>

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.