Struct CapeArrayStringOut

Source
pub struct CapeArrayStringOut<'a> {
    interface: &'a mut *mut ICapeArrayString,
    data: *mut *mut ICapeString,
    size: CapeSize,
}
Expand description

CapeArrayStringOut wraps an ICapeArrayString interface pointer.

Given a reference to an ICapeArrayString interface pointer, this allows setting and getting the elements.

This interface is typically used as arguments to rust methods on traits that are generated from CAPE-OPEN interfaces that have ICapeArrayString output arguments.

NULL interface pointers are not allowed.

§Examples

use cobia::*;

fn set_content(a: &mut CapeArrayStringOut) {
	a.put_array(&["idealGasEnthalpy", "idealGasEntropy"]).unwrap();
}
 
let mut arr = cobia::CapeArrayStringVec::new();
set_content(&mut CapeArrayStringOutFromProvider::from(&mut arr).as_cape_array_string_out());
assert_eq!(arr.as_string_vec(), vec!["idealGasEnthalpy".to_string(), "idealGasEntropy".to_string()]);

Fields§

§interface: &'a mut *mut ICapeArrayString§data: *mut *mut ICapeString§size: CapeSize

Implementations§

Source§

impl<'a> CapeArrayStringOut<'a>

Source

pub fn new(interface: &'a mut *mut ICapeArrayString) -> CapeArrayStringOut<'a>

Create a new CapeStringOut from an ICapeArrayString interface pointer.

§Arguments
  • interface - A pointer to an ICapeArrayString interface
§Examples
use cobia::*;
use cobia::prelude::*;
let mut arr = cobia::CapeArrayStringVec::from_slice(&vec!["idealGasEnthalpy".to_string(), "idealGasEntropy".to_string()]);
let i_cape_array_string=arr.as_cape_array_string_out();
let mut i_cape_array_string_ptr=(&i_cape_array_string as *const C::ICapeArrayString).cast_mut(); //normally a pointer to the interface is received
let sa = cobia::CapeArrayStringOut::new(&mut i_cape_array_string_ptr); //CapeArrayStringOut from *mut C::ICapeArrayString
assert_eq!(sa.as_string_vec(), vec!["idealGasEnthalpy".to_string(), "idealGasEntropy".to_string()]);
Source

pub fn as_string_vec(&self) -> Vec<String>

Return the content of the string array as a string vector.

§Examples
use cobia::*;
use cobia::prelude::*;
let mut arr = cobia::CapeArrayStringVec::from_slice(&vec!["idealGasEnthalpy".to_string(), "idealGasEntropy".to_string()]);
let i_cape_array_string=arr.as_cape_array_string_out();
let mut i_cape_array_string_ptr=(&i_cape_array_string as *const C::ICapeArrayString).cast_mut(); //normally a pointer to the interface is received
let sa = cobia::CapeArrayStringOut::new(&mut i_cape_array_string_ptr); //CapeArrayStringOut from *mut C::ICapeArrayString
assert_eq!(sa.as_string_vec(), vec!["idealGasEnthalpy".to_string(), "idealGasEntropy".to_string()]);
Source

pub fn size(&self) -> usize

Return the size of the vector

§Examples
use cobia::*;

fn test_size(a: &mut CapeArrayStringOut) {
	assert_eq!(a.size(), 2);
}
 
let mut arr = cobia::CapeArrayStringVec::from_slice(&vec!["idealGasEnthalpy".to_string(), "idealGasEntropy".to_string()]);
test_size(&mut CapeArrayStringOutFromProvider::from(&mut arr).as_cape_array_string_out());
Source

pub fn is_empty(&self) -> bool

Check if the array is empty

§Examples
use cobia::*;

fn test_empty(a: &mut CapeArrayStringOut) {
	assert!(a.is_empty());
}
 
let mut arr = cobia::CapeArrayStringVec::new();
test_empty(&mut CapeArrayStringOutFromProvider::from(&mut arr).as_cape_array_string_out());
Source

pub fn put_array<T: AsRef<str>>( &mut self, array: &[T], ) -> Result<(), COBIAError>

Set the content of the string array from a slice of string slices.

§Arguments
  • arr - A slice or array of vector of strings or string slices
§Examples
use cobia::*;

fn set_content(a: &mut CapeArrayStringOut) {
	a.put_array(&["idealGasEnthalpy", "idealGasEntropy"]).unwrap();
}
 
let mut arr = cobia::CapeArrayStringVec::new();
set_content(&mut CapeArrayStringOutFromProvider::from(&mut arr).as_cape_array_string_out());
assert_eq!(arr.as_string_vec(), vec!["idealGasEnthalpy".to_string(), "idealGasEntropy".to_string()]);
Source

pub fn at(&self, index: usize) -> Result<CapeStringOut<'a>, COBIAError>

Get an element

§Arguments
  • index - The index of the element to get

Note that neither Index and IndexMut is provided for CapeArrayStringOut, because these interfaces yield a reference to the element, whereas the elements of CapeArrayStringOut are represented by an interface, which is conveniently wrapped into CapeStringOut.

Note that the life time of the CapeStringOut is tied to the life time of the CapeArrayStringOut.

§Examples
use cobia::*;

fn test_element(a: &mut CapeArrayStringOut) {
	assert_eq!(a.at(1).unwrap().to_string(), "idealGasEntropy".to_string());
}
 
let mut arr = cobia::CapeArrayStringVec::from_slice(&vec!["idealGasEnthalpy".to_string(), "idealGasEntropy".to_string()]);
test_element(&mut CapeArrayStringOutFromProvider::from(&mut arr).as_cape_array_string_out());
Source

pub fn resize(&mut self, size: usize) -> Result<(), COBIAError>

Resize

§Arguments
  • size - The new size of the array
§Examples
use cobia::*;

fn set_content(a: &mut CapeArrayStringOut) {
	a.resize(3).unwrap();
	a.at(0).unwrap().set_string("idealGasEnthalpy").unwrap();
	a.at(1).unwrap().set_string("idealGasEntropy").unwrap();
	a.at(2).unwrap().set_string("density").unwrap();
}
 
let mut arr = cobia::CapeArrayStringVec::new();
set_content(&mut CapeArrayStringOutFromProvider::from(&mut arr).as_cape_array_string_out());
assert_eq!(arr.as_string_vec(), ["idealGasEnthalpy".to_string(), "idealGasEntropy".to_string(), "density".to_string()]); //the values have been stored on the object that implements ICapeArrayString
Source

pub fn set_string<T: AsRef<str>>( &mut self, index: usize, value: T, ) -> Result<(), COBIAError>

Set an element

§Arguments
  • index - The index of the element to set
  • value - The value to set
§Examples
use cobia::*;

fn set_content(a: &mut CapeArrayStringOut) {
	a.resize(3).unwrap();
	a.at(0).unwrap().set_string("idealGasEnthalpy").unwrap();
	a.at(1).unwrap().set_string("idealGasEntropy").unwrap();
	a.at(2).unwrap().set_string("density").unwrap();
}
 
let mut arr = cobia::CapeArrayStringVec::new();
set_content(&mut CapeArrayStringOutFromProvider::from(&mut arr).as_cape_array_string_out());
assert_eq!(arr.as_string_vec(), ["idealGasEnthalpy".to_string(), "idealGasEntropy".to_string(), "density".to_string()]); //the values have been stored on the object that implements ICapeArrayString
Source

pub fn set<T: CapeArrayStringProviderIn>( &mut self, array: &T, ) -> Result<(), COBIAError>

Set the content of the string array from any object that implements CapeArrayStringProviderIn.

§Arguments
  • array - An object that implements CapeArrayStringProviderIn
§Examples
use cobia::*;
let mut arr = cobia::CapeArrayStringVec::new();
let mut arr1 = cobia::CapeArrayStringVec::from_slice(&vec!["idealGasEnthalpy".to_string(), "idealGasEntropy".to_string()]);
CapeArrayStringOutFromProvider::from(&mut arr).as_cape_array_string_out().set(&arr1);
assert_eq!(arr.as_string_vec(), ["idealGasEnthalpy".to_string(), "idealGasEntropy".to_string()]); //the values have been stored on the object that implements ICapeArrayString
Source§

impl<'a> CapeArrayStringOut<'a>

Source

pub fn iter(&self) -> CapeArrayStringIterator<'_>

Return an iterator over the string array.

§Examples
use cobia::*;

fn test_iter(a: &mut CapeArrayStringOut) {
	let mut iter = a.iter();
	assert_eq!(iter.next().unwrap().to_string(), "idealGasEnthalpy".to_string());
	assert_eq!(iter.next().unwrap().to_string(), "idealGasEntropy".to_string());
	assert!(!iter.next().is_some());
}
 
let mut arr = cobia::CapeArrayStringVec::from_slice(&vec!["idealGasEnthalpy".to_string(), "idealGasEntropy".to_string()]);
test_iter(&mut CapeArrayStringOutFromProvider::from(&mut arr).as_cape_array_string_out());

Trait Implementations§

Source§

impl<'a> CapeArrayStringProviderOut for CapeArrayStringOut<'a>

Source§

fn as_cape_array_string_out(&mut self) -> ICapeArrayString

Convert to ICapeArrayString
Source§

impl<'a> Display for CapeArrayStringOut<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Display the content of the string array as a string vector.

§Examples
use cobia::*;

fn test_format(a: &mut CapeArrayStringOut) {
	assert_eq!(format!("{}", a), "[\"idealGasEnthalpy\", \"idealGasEntropy\"]");
}
 
let mut arr = cobia::CapeArrayStringVec::from_slice(&vec!["idealGasEnthalpy".to_string(), "idealGasEntropy".to_string()]);
test_format(&mut CapeArrayStringOutFromProvider::from(&mut arr).as_cape_array_string_out());

Auto Trait Implementations§

§

impl<'a> Freeze for CapeArrayStringOut<'a>

§

impl<'a> RefUnwindSafe for CapeArrayStringOut<'a>

§

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

§

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

§

impl<'a> Unpin for CapeArrayStringOut<'a>

§

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