Struct CapeArrayIn

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

Source

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

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

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

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

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

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>

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: &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>

Source§

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>

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 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§

type Output = Element

The returned type after indexing.
Source§

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

Source§

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 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 CapeArrayIn<'a, Element, Interface>

Source§

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

type Item = Element

The type of the elements being iterated over.
Source§

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

Which kind of iterator are we turning this into?

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<'a, Element, Interface> Unpin for CapeArrayIn<'a, Element, Interface>
where Interface: Unpin,

§

impl<'a, Element, Interface> UnwindSafe for CapeArrayIn<'a, Element, Interface>
where Element: RefUnwindSafe, Interface: UnwindSafe + RefUnwindSafe,

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.