pub struct CobiaCollectionBase<Element: CapeSmartPointer> {
interface: *mut ICobiaCollection,
element_type: PhantomData<Element>,
}Expand description
CobiaCollectionBase wraps an collection interface
The collection interface is returned in case muliple objects are returned by a method.
Collection items each must have a unique name, and the name is exposed from the approproate identification interface.
Collection items are accessed by index or by name.
#Example
use cobia;
use cobia::prelude::*;
cobia::cape_open_initialize().unwrap();
let library_enumerator = cobia::CapeTypeLibraries::new().unwrap();
let libraries = library_enumerator.libraries().unwrap(); //this is a CobiaCollection smart pointer
assert!(libraries.size() > 0); //normally the CAPE-OPEN type libraries are registered
cobia::cape_open_cleanup();Fields§
§interface: *mut ICobiaCollection§element_type: PhantomData<Element>Implementations§
Source§impl<Element: CapeSmartPointer> CobiaCollectionBase<Element>
impl<Element: CapeSmartPointer> CobiaCollectionBase<Element>
Sourcepub(crate) fn from_interface_pointer(interface: *mut ICobiaCollection) -> Self
pub(crate) fn from_interface_pointer(interface: *mut ICobiaCollection) -> Self
Create a new CobiaCollectionBase from an interface pointer
This member is not typically called. Instead, the CobiaCollectionBase is created by the API functions that return it.
§Safety
The interface pointer must be valid and must point to an object that implements the ICobiaCollection interface.
§Panics
This function panics if the interface pointer is null.
Sourcepub(crate) fn attach(interface: *mut ICobiaCollection) -> Self
pub(crate) fn attach(interface: *mut ICobiaCollection) -> Self
Create a new CobiaCollectionBase from an interface pointer without adding a reference
This member is not typically called. Instead, the CobiaCollectionBase is created by the API functions that return it.
§Safety
The interface pointer must be valid and must point to an object that implements the ICobiaCollection interface.
§Panics
This function panics if the interface pointer is null.
Sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
Get the number of elements in the collection
§Examples
use cobia;
use cobia::prelude::*;
cobia::cape_open_initialize().unwrap();
let library_enumerator = cobia::CapeTypeLibraries::new().unwrap();
let libraries = library_enumerator.libraries().unwrap(); //this is a CobiaCollection smart pointer
assert!(libraries.size() > 0); //normally the CAPE-OPEN type libraries are registered
cobia::cape_open_cleanup();Sourcepub fn at(&self, index: usize) -> Result<Element, COBIAError>
pub fn at(&self, index: usize) -> Result<Element, COBIAError>
Get a collection item by index in the collection
The index is zero-based, and must be 0 <= index < size().
Note that the collection implements iterators, but not the Index or IndexMut trait, as both these traits require returning the item by reference, which is not possible in this context, as the returned object owns the interface pointer.
§Examples
use cobia;
use cobia::prelude::*;
cobia::cape_open_initialize().unwrap();
let library_enumerator = cobia::CapeTypeLibraries::new().unwrap();
let libraries = library_enumerator.libraries().unwrap(); //this is a CobiaCollection smart pointer
assert!(libraries.size() > 0); //normally the CAPE-OPEN type libraries are registered
let library = libraries.at(0).unwrap();
cobia::cape_open_cleanup();Sourcepub fn get(&self, id: &str) -> Result<Element, COBIAError>
pub fn get(&self, id: &str) -> Result<Element, COBIAError>
Get a collection item by name
The name is case insentive, but must correspond to one of the items in the collection.
§Examples
use cobia;
use cobia::prelude::*;
cobia::cape_open_initialize().unwrap();
let library_enumerator = cobia::CapeTypeLibraries::new().unwrap();
let libraries = library_enumerator.libraries().unwrap(); //this is a CobiaCollection smart pointer
assert!(libraries.size() > 0); //normally the CAPE-OPEN type libraries are registered
let library = libraries.at(0).unwrap();
let lib_name = library.get_name().unwrap();
let library1 = libraries.get(&lib_name).unwrap();
assert_eq!(library.get_uuid().unwrap(),library1.get_uuid().unwrap());
cobia::cape_open_cleanup();Sourcepub fn iter(&self) -> CobiaCollectionBaseRefIterator<'_, Element> ⓘ
pub fn iter(&self) -> CobiaCollectionBaseRefIterator<'_, Element> ⓘ
Get an iterator for the collection by reference
This iterator does not consume the collection.
§Examples
use cobia;
use cobia::prelude::*;
cobia::cape_open_initialize().unwrap();
let library_enumerator = cobia::CapeTypeLibraries::new().unwrap();
let libraries = library_enumerator.libraries().unwrap(); //this is a CobiaCollection smart pointer
let mut found=false;
for library in libraries.iter() {
let lib_name = library.get_name().unwrap();
if lib_name=="CAPEOPEN_1_2" { //performance note: this is not efficient, but it is an example
found=true;
break;
}
}
assert!(found);
cobia::cape_open_cleanup();