Struct CapeArrayOut

Source
pub struct CapeArrayOut<'a, Element: Copy + Clone, Interface: ArrayInterface<Element>> {
    pub(crate) interface: &'a mut *mut Interface,
    data: *mut Element,
    size: CapeSize,
}
Expand description

CapeArrayOut wraps an ICapeArray interface pointer.

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

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

This class takes a mutable reference to the interface, 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)

NULL pointers are not allowed here

§Examples

use cobia::*;

fn set_content(arr: &mut CapeArrayRealOut) {
	arr.put_array(&[4.5,6.5]).unwrap();
}
 
let mut arr = cobia::CapeArrayRealVec::from_slice(&[4.5,6.5]);
set_content(&mut CapeArrayRealOutFromProvider::from(&mut arr).as_cape_array_real_out());
assert_eq!(arr.as_vec(), &vec![4.5,6.5]);

Fields§

§interface: &'a mut *mut Interface§data: *mut Element§size: CapeSize

Implementations§

Source§

impl<'a, Element: Copy + Clone, Interface: ArrayInterface<Element>> CapeArrayOut<'a, Element, Interface>

Source

pub fn new(interface: &'a mut *mut Interface) -> Self

Create a new CapeArrayOut from an ICapeArray interface pointer.

§Arguments
  • interface - A pointer to an ICapeArray interface
§Examples
use cobia::*;
use cobia::prelude::*;
let mut arr = cobia::CapeArrayRealVec::from_slice(&[4.6,8.6,1e-3]);
let i_cape_array_real=arr.as_cape_array_real_out();
let mut i_cape_array_real_ptr=(&i_cape_array_real as *const C::ICapeArrayReal).cast_mut(); //normally a pointer to the interface is received
let a = cobia::CapeArrayRealOut::new(&mut i_cape_array_real_ptr); //CapeArrayRealOut from *mut C::ICapeArrayReal
assert_eq!(a.as_vec(), vec![4.6,8.6,1e-3]);
Source

pub fn size(&self) -> usize

Return the size of the array

§Examples
use cobia::*;

fn test_content(arr: &mut CapeArrayRealOut) {
	assert_eq!(arr.size(), 3);
}
 
let mut arr = cobia::CapeArrayRealVec::from_slice(&[3.5,5.5,8.2]);
test_content(&mut CapeArrayRealOutFromProvider::from(&mut arr).as_cape_array_real_out());
Source

pub fn is_empty(&self) -> bool

Check if the array is empty

§Examples
use cobia::*;

fn check_not_empty(arr: &mut CapeArrayRealOut) {
	assert!(!arr.is_empty());
}
 
let mut arr = cobia::CapeArrayRealVec::from_slice(&[3.5,5.5,8.2]);
check_not_empty(&mut CapeArrayRealOutFromProvider::from(&mut arr).as_cape_array_real_out());
Source

pub fn as_vec(&self) -> Vec<Element>

Return the content of the array as a vector.

§Examples
use cobia::*;

fn check_content(a: &mut CapeArrayRealOut) {
	assert_eq!(a.as_vec(), vec![1.2,1.4,1.6]);
}
 
let mut arr = cobia::CapeArrayRealVec::from_slice(&[1.2,1.4,1.6]);
check_content(&mut CapeArrayRealOutFromProvider::from(&mut arr).as_cape_array_real_out());
Source

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

Set the content of the array from a slice

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

fn set_content(arr: &mut CapeArrayRealOut) {
	arr.put_array(&[3.1,3.2,3.3,3.4]).unwrap();
}
 
let mut arr = cobia::CapeArrayRealVec::from_slice(&[4.5,6.5]);
set_content(&mut CapeArrayRealOutFromProvider::from(&mut arr).as_cape_array_real_out());
assert_eq!(arr.as_vec(), &vec![3.1,3.2,3.3,3.4]); //the values have been stored on the object that implements ICapeArrayReal
Source

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

Resize the array

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

fn resize_array(a: &mut CapeArrayRealOut) {
	a.resize(4).unwrap();
}
 
let mut arr = cobia::CapeArrayRealVec::new();
resize_array(&mut CapeArrayRealOutFromProvider::from(&mut arr).as_cape_array_real_out());
assert_eq!(arr.size(), 4); 
Source

pub fn as_slice(&self) -> &[Element]

Return the content of the real array as a real slice.

§Examples
use cobia::*;

fn check_content(a: &mut CapeArrayRealOut) {
	assert_eq!(a.as_slice(), &[1.2,1.4,1.6])
}
 
let mut arr = cobia::CapeArrayRealVec::from_slice(&[1.2,1.4,1.6]);
check_content(&mut CapeArrayRealOutFromProvider::from(&mut arr).as_cape_array_real_out());
Source

pub fn iter(&self) -> CapeArrayRefIterator<'_, Element>

Return an iterator for the array.

§Examples
use cobia::*;

fn check_iter(a: &mut CapeArrayRealOut) {
	 let mut iter = a.iter();
	 assert_eq!(iter.next().unwrap(), 0.1);
	 assert_eq!(iter.next().unwrap(), 0.2);
	 assert!(!iter.next().is_some());
}
 
let mut arr = cobia::CapeArrayRealVec::from_vec(vec![0.1,0.2]);
check_iter(&mut CapeArrayRealOutFromProvider::from(&mut arr).as_cape_array_real_out());
Source§

impl<'a> CapeArrayOut<'a, f64, ICapeArrayReal>

Source

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

Set the content of the real array from any object that implements CapeArrayRealProviderIn.

§Arguments
  • array - An object that implements CapeArrayRealProviderIn
§Examples
use cobia::*;
let mut arr = cobia::CapeArrayRealVec::new();
let mut arr1 = cobia::CapeArrayRealVec::from_slice(&vec![125.1,-19.4,3.14]);
CapeArrayRealOutFromProvider::from(&mut arr).as_cape_array_real_out().set(&arr1);
assert_eq!(arr.as_vec(), &[125.1,-19.4,3.14]);
Source§

impl<'a> CapeArrayOut<'a, i32, ICapeArrayInteger>

Source

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

Set the content of the integer array from any object that implements CapeArrayIntegerProviderIn.

§Arguments
  • array - An object that implements CapeArrayIntegerProviderIn
§Examples
use cobia::*;
let mut arr = cobia::CapeArrayIntegerVec::new();
let mut arr1 = cobia::CapeArrayIntegerVec::from_slice(&vec![17,14,9,0]);
CapeArrayIntegerOutFromProvider::from(&mut arr).as_cape_array_integer_out().set(&arr1);
assert_eq!(arr.as_vec(), &[17,14,9,0]);
Source§

impl<'a> CapeArrayOut<'a, u8, ICapeArrayByte>

Source

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

Set the content of the byte array from any object that implements CapeArrayByteProviderIn.

§Arguments
  • array - An object that implements CapeArrayByteProviderIn
§Examples
use cobia::*;
let mut arr = cobia::CapeArrayByteVec::new();
let mut arr1 = cobia::CapeArrayByteVec::from_slice(&vec![2u8,8u8,10u8]);
CapeArrayByteOutFromProvider::from(&mut arr).as_cape_array_byte_out().set(&arr1);
assert_eq!(arr.as_vec(), &[2u8,8u8,10u8]);
Source§

impl<'a> CapeArrayOut<'a, u32, ICapeArrayBoolean>

Source

pub fn as_bool_vec(&self) -> Vec<bool>

Returns the elements of the array as a Vec<bool>.

§Examples
use cobia::*;

fn test_content(a: CapeArrayBooleanOut) {
    assert_eq!(a.as_bool_vec(), vec![false,true,true,false]);
}
 
let mut arr = cobia::CapeArrayBooleanVec::from_bool_slice(&[false,true,true,false]);
test_content(CapeArrayBooleanOutFromProvider::from(&mut arr).as_cape_array_boolean_out())
Source

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

Set the content of the boolean array from any object that implements CapeArrayBooleanProviderIn.

§Arguments
  • array - An object that implements CapeArrayBooleanProviderIn
§Examples
use cobia::*;
fn set_content(a: &mut CapeArrayBooleanOut, b: &CapeArrayBooleanIn) {
	a.put_array(&[false as CapeBoolean,true as CapeBoolean,true as CapeBoolean,false as CapeBoolean]).unwrap();
}
 
let mut arr = cobia::CapeArrayBooleanVec::new();
let arr1 = cobia::CapeArrayBooleanVec::from_bool_slice(&[false,true,true,false]);
set_content(&mut CapeArrayBooleanOutFromProvider::from(&mut arr).as_cape_array_boolean_out(),&CapeArrayBooleanInFromProvider::from(&arr1).as_cape_array_boolean_in());
assert_eq!(arr.as_vec(), &[false as CapeBoolean,true as CapeBoolean,true as CapeBoolean,false as CapeBoolean]);

Trait Implementations§

Source§

impl<'a, Element: Copy + Clone + Display, Interface: ArrayInterface<Element>> Display for CapeArrayOut<'a, Element, Interface>

Source§

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

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

§Examples
use cobia::*;

fn check_format(a: &mut CapeArrayRealOut) {
	 assert_eq!(format!("{}", a), "[1, 1.1, 1.2]");
}
 
let mut arr = cobia::CapeArrayRealVec::from_vec(vec![1.0,1.1,1.2]);
check_format(&mut CapeArrayRealOutFromProvider::from(&mut arr).as_cape_array_real_out());
Source§

impl<'a, Element: Copy + Clone, Interface: ArrayInterface<Element>> Index<usize> for CapeArrayOut<'a, Element, Interface>

Source§

fn index(&self, index: usize) -> &Self::Output

Indexing

Returns a reference to the string at the given index.

§Arguments
  • index - The index of the string to be returned
§Examples
use cobia::*;

fn check_item(a: &mut CapeArrayRealOut) {
	 assert_eq!(a[1], 10.2);
}
 
let mut arr = cobia::CapeArrayRealVec::from_slice(&[10.1,10.2,10.3]);
check_item(&mut CapeArrayRealOutFromProvider::from(&mut arr).as_cape_array_real_out());
Source§

type Output = Element

The returned type after indexing.
Source§

impl<'a, Element: Copy + Clone, Interface: ArrayInterface<Element>> IndexMut<usize> for CapeArrayOut<'a, Element, Interface>

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Indexing

Returns a mutable reference to the string at the given index.

§Arguments
  • index - The index of the string to be returned
§Examples
use cobia::*;

fn set_item(a: &mut CapeArrayRealOut) {
	a[1]=5.3;
}
 
let mut arr = cobia::CapeArrayRealVec::from_slice(&[10.1,10.2,10.3]);
set_item(&mut CapeArrayRealOutFromProvider::from(&mut arr).as_cape_array_real_out());
assert_eq!(arr.as_vec(), &vec![10.1,5.3,10.3]);
Source§

impl<'a, Element: Copy + Clone + 'a, Interface: ArrayInterface<Element>> IntoIterator for &'a CapeArrayOut<'a, Element, Interface>

Source§

fn into_iter(self) -> CapeArrayRefIterator<'a, Element>

Return an iterator over the real array.

§Examples
use cobia::*;

fn check_iter(a: CapeArrayRealOut) {
	let mut sum=0.0;
	for val in &a {
	    sum+=val;
	}
	assert!((sum-0.9).abs()<1e-12);
}
 
let mut arr = cobia::CapeArrayRealVec::from_vec(vec![0.3,0.6]);
check_iter(CapeArrayRealOutFromProvider::from(&mut arr).as_cape_array_real_out());
Source§

type Item = Element

The type of the elements being iterated over.
Source§

type IntoIter = CapeArrayRefIterator<'a, Element>

Which kind of iterator are we turning this into?
Source§

impl<'a, Element: Copy + Clone, Interface: ArrayInterface<Element>> IntoIterator for CapeArrayOut<'a, Element, Interface>

Source§

fn into_iter(self) -> Self::IntoIter

Return an iterator over the real array.

§Examples
use cobia::*;

fn check_iter(a: CapeArrayRealOut) {
	let mut sum=0.0;
	for val in a {
	    sum+=val;
	}
	assert!((sum-0.9).abs()<1e-12);
}
 
let mut arr = cobia::CapeArrayRealVec::from_vec(vec![0.3,0.6]);
check_iter(CapeArrayRealOutFromProvider::from(&mut arr).as_cape_array_real_out());
Source§

type Item = Element

The type of the elements being iterated over.
Source§

type IntoIter = CapeArrayOutIterator<'a, Element, Interface>

Which kind of iterator are we turning this into?

Auto Trait Implementations§

§

impl<'a, Element, Interface> Freeze for CapeArrayOut<'a, Element, Interface>

§

impl<'a, Element, Interface> RefUnwindSafe for CapeArrayOut<'a, Element, Interface>
where Element: RefUnwindSafe, Interface: RefUnwindSafe,

§

impl<'a, Element, Interface> !Send for CapeArrayOut<'a, Element, Interface>

§

impl<'a, Element, Interface> !Sync for CapeArrayOut<'a, Element, Interface>

§

impl<'a, Element, Interface> Unpin for CapeArrayOut<'a, Element, Interface>

§

impl<'a, Element, Interface> !UnwindSafe for CapeArrayOut<'a, Element, Interface>

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.