pub struct CapeArrayIn<'a, Element: Copy + Clone, Interface: ArrayInterface<Element>> {
data: *const Element,
size: CapeSize,
pub(crate) interface: &'a *mut Interface,
_lifetime: PhantomData<&'a ()>,
_interface_type: PhantomData<Interface>,
}Expand description
CapeArrayIn wraps an ICapeArray interface pointer.
Given a reference to an ICapeArray interface pointer, this allows gettings, but not setting, the elements.
This interface is typically used as input arguments to rust methods on traits that are generated from CAPE-OPEN interfaces that have ICapeArray arguments.
This class takes a reference to the interface pointer. A NULL pointer is treated as an empty array.
§Examples
use cobia::*;
fn test_content(arr: &CapeArrayRealIn) {
assert_eq!(arr.as_vec(), vec![4.6,8.6,1e-3]);
}
let arr = cobia::CapeArrayRealSlice::new(&[4.6,8.6,1e-3]);
test_content(&CapeArrayRealInFromProvider::from(&arr).as_cape_array_real_in())Fields§
§data: *const Element§size: CapeSize§interface: &'a *mut Interface§_lifetime: PhantomData<&'a ()>§_interface_type: PhantomData<Interface>Implementations§
Source§impl<'a, Element: Copy + Clone, Interface: ArrayInterface<Element>> CapeArrayIn<'a, Element, Interface>
impl<'a, Element: Copy + Clone, Interface: ArrayInterface<Element>> CapeArrayIn<'a, Element, Interface>
Sourcepub fn new(interface: &'a *mut Interface) -> Self
pub fn new(interface: &'a *mut Interface) -> Self
Create a new CapeArrayIn from an ICapeArray interface pointer.
§Arguments
interface- A pointer to an ICapeArray interface
§Examples
use cobia::*;
use cobia::prelude::*;
let arr = cobia::CapeArrayRealSlice::new(&[4.5,6.5]);
let mut i_cape_array_real=arr.as_cape_array_real_in();
let 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::CapeArrayRealIn::new(&i_cape_array_real_ptr); //CapeArrayRealIn from *mut C::ICapeArrayReal
assert_eq!(a.as_vec(), vec![4.5,6.5]);Sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
Return the size of the array
§Examples
use cobia::*;
fn test_size(arr: &CapeArrayRealIn) {
assert_eq!(arr.size(), 3);
}
let arr = cobia::CapeArrayRealVec::from_slice(&[3.5,5.5,8.2]);
test_size(&CapeArrayRealInFromProvider::from(&arr).as_cape_array_real_in())Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Check if the array is empty
§Examples
use cobia::*;
fn test_not_empty(arr: &CapeArrayRealIn) {
assert!(!arr.is_empty());
}
let arr = cobia::CapeArrayRealVec::from_slice(&[3.5,5.5,8.2]);
test_not_empty(&CapeArrayRealInFromProvider::from(&arr).as_cape_array_real_in())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 test_content(arr: &CapeArrayRealIn) {
assert_eq!(arr.as_vec(), vec![1.2,1.4,1.6]);
}
let arr = cobia::CapeArrayRealSlice::new(&[1.2,1.4,1.6]);
test_content(&CapeArrayRealInFromProvider::from(&arr).as_cape_array_real_in())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 test_content(arr: &CapeArrayRealIn) {
assert_eq!(arr.as_slice(), &[1.2,1.4,1.6]);
}
let arr = cobia::CapeArrayRealVec::from_vec(vec![1.2,1.4,1.6]);
test_content(&CapeArrayRealInFromProvider::from(&arr).as_cape_array_real_in())Sourcepub fn iter(&self) -> CapeArrayRefIterator<'_, Element> ⓘ
pub fn iter(&self) -> CapeArrayRefIterator<'_, Element> ⓘ
Return an iterator for the array.
§Examples
use cobia::*;
fn test_iter(a: &CapeArrayRealIn) {
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 arr = cobia::CapeArrayRealVec::from_vec(vec![0.1,0.2]);
test_iter(&CapeArrayRealInFromProvider::from(&arr).as_cape_array_real_in())Source§impl<'a> CapeArrayIn<'a, u32, ICapeArrayBoolean>
impl<'a> CapeArrayIn<'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: &CapeArrayBooleanIn) {
assert_eq!(a.as_bool_vec(), vec![false,true,true,false]);
}
let arr = cobia::CapeArrayBooleanVec::from_bool_slice(&[false,true,true,false]);
test_content(&CapeArrayBooleanInFromProvider::from(&arr).as_cape_array_boolean_in())Trait Implementations§
Source§impl<'a, Element: Copy + Clone + Display, Interface: ArrayInterface<Element>> Display for CapeArrayIn<'a, Element, Interface>
impl<'a, Element: Copy + Clone + Display, Interface: ArrayInterface<Element>> Display for CapeArrayIn<'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 test_format(a : &CapeArrayRealIn) {
assert_eq!(format!("{}", a), "[1, 1.1, 1.2]");
}
let arr = cobia::CapeArrayRealVec::from_vec(vec![1.0,1.1,1.2]);
test_format(&CapeArrayRealInFromProvider::from(&arr).as_cape_array_real_in())Source§impl<'a, Element: Copy + Clone, Interface: ArrayInterface<Element>> Index<usize> for CapeArrayIn<'a, Element, Interface>
impl<'a, Element: Copy + Clone, Interface: ArrayInterface<Element>> Index<usize> for CapeArrayIn<'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 test_element(arr: &CapeArrayRealIn) {
assert_eq!(arr[1], 10.2);
}
let arr = cobia::CapeArrayRealSlice::new(&[10.1,10.2,10.3]);
test_element(&CapeArrayRealInFromProvider::from(&arr).as_cape_array_real_in())Source§impl<'a, Element: Copy + Clone + 'a, Interface: ArrayInterface<Element>> IntoIterator for &'a CapeArrayIn<'a, Element, Interface>
impl<'a, Element: Copy + Clone + 'a, Interface: ArrayInterface<Element>> IntoIterator for &'a CapeArrayIn<'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 test_iter(a: &CapeArrayRealIn) {
let mut sum=0.0;
for val in a {
sum+=val;
}
assert!((sum-0.9).abs()<1e-12);
}
let arr = cobia::CapeArrayRealVec::from_vec(vec![0.3,0.6]);
test_iter(&CapeArrayRealInFromProvider::from(&arr).as_cape_array_real_in())Source§type IntoIter = CapeArrayRefIterator<'a, Element>
type IntoIter = CapeArrayRefIterator<'a, Element>
Source§impl<'a, Element: Copy + Clone, Interface: ArrayInterface<Element>> IntoIterator for CapeArrayIn<'a, Element, Interface>
impl<'a, Element: Copy + Clone, Interface: ArrayInterface<Element>> IntoIterator for CapeArrayIn<'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 test_iter(a: &CapeArrayRealIn) {
let mut sum=0.0;
for val in a {
sum+=val;
}
assert!((sum-0.9).abs()<1e-12);
}
let arr = cobia::CapeArrayRealVec::from_vec(vec![0.3,0.6]);
test_iter(&CapeArrayRealInFromProvider::from(&arr).as_cape_array_real_in())