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: CapeSizeImplementations§
Source§impl<'a, Element: Copy + Clone, Interface: ArrayInterface<Element>> CapeArrayOut<'a, Element, Interface>
impl<'a, Element: Copy + Clone, Interface: ArrayInterface<Element>> CapeArrayOut<'a, Element, Interface>
Sourcepub fn new(interface: &'a mut *mut Interface) -> Self
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]);Sourcepub fn size(&self) -> usize
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());Sourcepub fn is_empty(&self) -> bool
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());Sourcepub fn as_vec(&self) -> Vec<Element>
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());Sourcepub fn put_array(&mut self, array: &[Element]) -> Result<(), COBIAError>
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 ICapeArrayRealSourcepub fn resize(&mut self, size: usize) -> Result<(), COBIAError>
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); Sourcepub fn as_slice(&self) -> &[Element]
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());Sourcepub fn iter(&self) -> CapeArrayRefIterator<'_, Element> ⓘ
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>
impl<'a> CapeArrayOut<'a, f64, ICapeArrayReal>
Sourcepub fn set<T: CapeArrayRealProviderIn>(
&mut self,
array: &T,
) -> Result<(), COBIAError>
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>
impl<'a> CapeArrayOut<'a, i32, ICapeArrayInteger>
Sourcepub fn set<T: CapeArrayIntegerProviderIn>(
&mut self,
array: &T,
) -> Result<(), COBIAError>
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>
impl<'a> CapeArrayOut<'a, u8, ICapeArrayByte>
Sourcepub fn set<T: CapeArrayByteProviderIn>(
&mut self,
array: &T,
) -> Result<(), COBIAError>
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>
impl<'a> CapeArrayOut<'a, u32, ICapeArrayBoolean>
Sourcepub fn as_bool_vec(&self) -> Vec<bool>
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())Sourcepub fn set<T: CapeArrayBooleanProviderIn>(
&mut self,
array: &T,
) -> Result<(), COBIAError>
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>
impl<'a, Element: Copy + Clone + Display, Interface: ArrayInterface<Element>> Display for CapeArrayOut<'a, Element, Interface>
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
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>
impl<'a, Element: Copy + Clone, Interface: ArrayInterface<Element>> Index<usize> for CapeArrayOut<'a, Element, Interface>
Source§fn index(&self, index: usize) -> &Self::Output
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§impl<'a, Element: Copy + Clone, Interface: ArrayInterface<Element>> IndexMut<usize> for CapeArrayOut<'a, Element, Interface>
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
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>
impl<'a, Element: Copy + Clone + 'a, Interface: ArrayInterface<Element>> IntoIterator for &'a CapeArrayOut<'a, Element, Interface>
Source§fn into_iter(self) -> CapeArrayRefIterator<'a, Element> ⓘ
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 IntoIter = CapeArrayRefIterator<'a, Element>
type IntoIter = CapeArrayRefIterator<'a, Element>
Source§impl<'a, Element: Copy + Clone, Interface: ArrayInterface<Element>> IntoIterator for CapeArrayOut<'a, Element, Interface>
impl<'a, Element: Copy + Clone, Interface: ArrayInterface<Element>> IntoIterator for CapeArrayOut<'a, Element, Interface>
Source§fn into_iter(self) -> Self::IntoIter
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());