Struct CapeValueIn

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

Implementations§

Source§

impl<'a> CapeValueIn<'a>

Source

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

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

Source§

fn as_cape_value_in(&self) -> ICapeValue

Convert to ICapeValue
Source§

impl<'a> Display for CapeValueIn<'a>

Source§

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

Auto Trait Implementations§

§

impl<'a> Freeze for CapeValueIn<'a>

§

impl<'a> RefUnwindSafe for CapeValueIn<'a>

§

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

§

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

§

impl<'a> Unpin for CapeValueIn<'a>

§

impl<'a> UnwindSafe for CapeValueIn<'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.