pub struct Struct<P>(/* private fields */);Expand description
ND Structure array.
Implementations§
Source§impl<'p, P: MatlabPtr + 'p> Struct<P>
impl<'p, P: MatlabPtr + 'p> Struct<P>
Sourcepub fn into_scalar(self) -> Result<ScalarStruct<P>, Self>
pub fn into_scalar(self) -> Result<ScalarStruct<P>, Self>
If the structure array only holds one element, convert it to a type that reflects that
Sourcepub fn field_number(&self, field: &CStr) -> Result<i32, StructError>
pub fn field_number(&self, field: &CStr) -> Result<i32, StructError>
Determine the field number for some field name.
NOTE: field numbers are not static; if a new field is added or removed the field numbers change. The only reliable way accessing fields is via their name.
Sourcepub fn field_name(&self, fieldnum: i32) -> Result<&'p CStr, StructError>
pub fn field_name(&self, fieldnum: i32) -> Result<&'p CStr, StructError>
Determine the field name of the fieldnumth field.
Sourcepub fn field_names(&self) -> impl Iterator<Item = &'p CStr> + '_
pub fn field_names(&self) -> impl Iterator<Item = &'p CStr> + '_
Iterate over all the field names of this struct
Sourcepub fn get<I: Index, F: FieldIndex>(
&self,
idx: I,
field: F,
) -> Result<Option<&'p mxArray>, StructError>
pub fn get<I: Index, F: FieldIndex>( &self, idx: I, field: F, ) -> Result<Option<&'p mxArray>, StructError>
Get the field of some structure within this array.
Sourcepub fn fields<F: FieldIndex>(
&self,
field: F,
) -> Result<impl Iterator<Item = Option<&'p mxArray>> + '_, StructError>
pub fn fields<F: FieldIndex>( &self, field: F, ) -> Result<impl Iterator<Item = Option<&'p mxArray>> + '_, StructError>
Get an iterator which returns references to the fields of each child
structure. So, e.g.: s(1).field, s(2).field, etc.
Source§impl<'p, P: MutMatlabPtr + 'p> Struct<P>
impl<'p, P: MutMatlabPtr + 'p> Struct<P>
pub fn as_ref_struct<'s>(&'s self) -> Struct<&'s mxArray>
Sourcepub fn get_mut<I: Index, F: FieldIndex>(
&mut self,
idx: I,
field: F,
) -> Result<Option<&'p mut mxArray>, StructError>
pub fn get_mut<I: Index, F: FieldIndex>( &mut self, idx: I, field: F, ) -> Result<Option<&'p mut mxArray>, StructError>
Get a mutable access to the field of some child struct.
Sourcepub fn set<I: Index, F: FieldIndex>(
&mut self,
idx: I,
field: F,
value: MxArray,
) -> Result<Option<MxArray>, StructError>
pub fn set<I: Index, F: FieldIndex>( &mut self, idx: I, field: F, value: MxArray, ) -> Result<Option<MxArray>, StructError>
Set the value of a field of some child struct. Returns the previous value, if there was any.
Sourcepub fn replace<I: Index, F: FieldIndex>(
&mut self,
idx: I,
field: F,
value: Option<MxArray>,
) -> Result<Option<MxArray>, StructError>
pub fn replace<I: Index, F: FieldIndex>( &mut self, idx: I, field: F, value: Option<MxArray>, ) -> Result<Option<MxArray>, StructError>
Replace the current value of some child struct. This can be either None
(removing the element), or Some(value) (in which case it replaces the old
value). In either case, it returns what was previously there, which can also
be None or Some(value).
Sourcepub fn unset<I: Index, F: FieldIndex>(
&mut self,
idx: I,
field: F,
) -> Result<Option<MxArray>, StructError>
pub fn unset<I: Index, F: FieldIndex>( &mut self, idx: I, field: F, ) -> Result<Option<MxArray>, StructError>
Unset a struct field by setting it to None. See replace.
Sourcepub fn fields_mut<F: FieldIndex>(
&mut self,
field: F,
) -> Result<impl Iterator<Item = Option<&'p mut mxArray>> + '_, StructError>
pub fn fields_mut<F: FieldIndex>( &mut self, field: F, ) -> Result<impl Iterator<Item = Option<&'p mut mxArray>> + '_, StructError>
Return an iterator, returning mutable references to a field on each struct in
the array, as with Struct::fields.
Sourcepub fn fields_values<F: FieldIndex>(
&mut self,
field: F,
) -> Result<impl Iterator<Item = Option<MxArray>> + '_, StructError>
pub fn fields_values<F: FieldIndex>( &mut self, field: F, ) -> Result<impl Iterator<Item = Option<MxArray>> + '_, StructError>
Return an iterator, yielding the values of a field on each struct in the
array. This will set each yielded field to None. Also see
Struct::fields.
Sourcepub fn add_field(&mut self, field: &CStr) -> Result<i32, i32>
pub fn add_field(&mut self, field: &CStr) -> Result<i32, i32>
Add a field to the structure array. If the field does not yet exist, it
returns Ok(new_field_num); if the field already exists it returns
Err(existing_field_number).
Since no values for the fields are provided, they are initialised with
None.
If you’re not interested in whether the field existed or not, you can obtain the field number to the field you wanted to add with:
use std::convert::identity as idtt;
let fieldnum = s.add_field(name).map_or_else(idtt, idtt)NOTE that the field number is not static; if the structure array layout is mutated (e.g. a new field being added or removed), the field numbers for the fields may change.
Sourcepub fn remove_field<F: FieldIndex>(
&mut self,
field: F,
) -> Result<(), StructError>
pub fn remove_field<F: FieldIndex>( &mut self, field: F, ) -> Result<(), StructError>
Remove a field from a structure array without dropping and freeing their
values. See Struct::delete_field instead
Sourcepub fn delete_field<F: FieldIndex>(
&mut self,
field: F,
) -> Result<(), StructError>
pub fn delete_field<F: FieldIndex>( &mut self, field: F, ) -> Result<(), StructError>
Removes a field from a structure array, dropping and freeing their resources in the process.
Methods from Deref<Target = mxArray>§
Sourcepub fn duplicate(&self) -> MxArray
pub fn duplicate(&self) -> MxArray
Create a deep copy of the array, and return as an owned type. However,
consider using MatlabClass::duplicate instead if you are already working
with MatlabClasses.
Sourcepub fn dimensions(&self) -> &[usize]
pub fn dimensions(&self) -> &[usize]
Return the sizes of the constituent dimensions of the mxArray
Sourcepub fn raw_class_id(&self) -> u32
pub fn raw_class_id(&self) -> u32
Return the raw class ID; the number Matlab returns.
Sourcepub fn class_id(&self) -> Result<ClassID, u32>
pub fn class_id(&self) -> Result<ClassID, u32>
Return Ok(ClassID) for mxArrays which map to a built-in class (such as
numeric arrays, structure arrays, and cell arrays (see ClassID);
otherwise it returns the raw class ID in the Err variant. These other
values of the raw class ID are used in modern versions of Matlab for custom
classes, defined via e..g classdef.
Sourcepub fn is_complex(&self) -> bool
pub fn is_complex(&self) -> bool
Check whether the backing array is complex. Since the only arrays which can be complex are numeric arrays, this also implies that.
pub fn complexity(&self) -> Complexity
Trait Implementations§
Source§impl<P> DerefMut for Struct<P>where
P: MutMatlabPtr,
impl<P> DerefMut for Struct<P>where
P: MutMatlabPtr,
Source§impl<'a> FromMatlab<'a> for Struct<&'a mxArray>
impl<'a> FromMatlab<'a> for Struct<&'a mxArray>
fn from_matlab(mx: &'a mxArray) -> Result<Self, FromMatlabError<&'a mxArray>>
Source§impl<'p, P: MatlabPtr + 'p> MatlabClass<P> for Struct<P>
impl<'p, P: MatlabPtr + 'p> MatlabClass<P> for Struct<P>
Source§fn from_mx_array(mx: P) -> Result<Self, FromMatlabError<P>>
fn from_mx_array(mx: P) -> Result<Self, FromMatlabError<P>>
MatlabPtr. If the type requirements of
the class match what the pointer is, then the class is constructed. Otherwise,
an error is returned; containing the reason of the failure and the original
pointer. The latter is especially useful with MxArrays; the owned
MatlabPtr type — otherwise it would be dropped.Source§fn into_inner(self) -> P
fn into_inner(self) -> P
MatlabClass back to a bare MatlabPtr.Source§impl<'p, P: MutMatlabPtr + 'p> MutMatlabClass<P> for Struct<P>
impl<'p, P: MutMatlabPtr + 'p> MutMatlabClass<P> for Struct<P>
type AsBorrowed<'a> = Struct<&'a mxArray_tag> where P: 'a
fn as_borrowed<'a>(&'a self) -> Self::AsBorrowed<'a>
fn inner_mut(&mut self) -> &mut P
Source§impl OwnedMatlabClass for Struct<MxArray>
impl OwnedMatlabClass for Struct<MxArray>
Source§type AsMutable<'a> = Struct<&'a mut mxArray_tag>
where
Self: 'a
type AsMutable<'a> = Struct<&'a mut mxArray_tag> where Self: 'a
Source§fn as_mutable<'a>(&'a mut self) -> Self::AsMutable<'a>
fn as_mutable<'a>(&'a mut self) -> Self::AsMutable<'a>
MutMatlabClass from this owned instance.