Struct

Struct Struct 

Source
pub struct Struct<P>(/* private fields */);
Expand description

ND Structure array.

Implementations§

Source§

impl<'p, P: MatlabPtr + 'p> Struct<P>

Source

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

Source

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.

Source

pub fn field_name(&self, fieldnum: i32) -> Result<&'p CStr, StructError>

Determine the field name of the fieldnumth field.

Source

pub fn field_names(&self) -> impl Iterator<Item = &'p CStr> + '_

Iterate over all the field names of this struct

Source

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.

Source

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>

Source

pub fn as_ref_struct<'s>(&'s self) -> Struct<&'s mxArray>

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source§

impl Struct<MxArray>

Source

pub fn new_empty_with_fields(fieldnames: &[&CStr]) -> Self

Create an empty struct but with field names.

Source

pub fn new(shape: &[usize], fieldnames: &[&CStr]) -> Self

Create a new structure array with the given fieldnames.

Methods from Deref<Target = mxArray>§

Source

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.

Source

pub fn dimensions(&self) -> &[usize]

Return the sizes of the constituent dimensions of the mxArray

Source

pub fn numel(&self) -> usize

Return the number of elements contained in this array.

Source

pub fn raw_class_id(&self) -> u32

Return the raw class ID; the number Matlab returns.

Source

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.

Source

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.

Source

pub fn is_sparse(&self) -> bool

Check whether the backing array is a sparse matrix

Source

pub fn is_struct(&self) -> bool

Check whether the backing array is a struct array

Source

pub fn is_empty(&self) -> bool

Check whether the backing array is empty

Source

pub fn is_scalar(&self) -> bool

Check whether the backing array only holds one element

Source

pub fn complexity(&self) -> Complexity

Trait Implementations§

Source§

impl<P: Clone> Clone for Struct<P>

Source§

fn clone(&self) -> Struct<P>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<P: Debug> Debug for Struct<P>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<P> Deref for Struct<P>
where P: MatlabPtr,

Source§

type Target = mxArray_tag

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<P> DerefMut for Struct<P>
where P: MutMatlabPtr,

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<'a> FromMatlab<'a> for Struct<&'a mxArray>

Source§

impl<P: Hash> Hash for Struct<P>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'p, P: MatlabPtr + 'p> MatlabClass<P> for Struct<P>

Source§

type Owned = Struct<MxArray>

The owned variant of this matlab class.
Source§

fn from_mx_array(mx: P) -> Result<Self, FromMatlabError<P>>

Try to build a matlab class from a 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

Deconstruct the MatlabClass back to a bare MatlabPtr.
Source§

fn inner(&self) -> &P

Get a reference to the inner MatlabPtr. However, note that for &mxArray and &mut mxArray, the returned references will be of type &&mxArray and &&mut mxArray.
Source§

fn duplicate(&self) -> Self::Owned

Make a deep clone of the inner MatlabPtr, and construct an Owned MatlabClass from it.
Source§

impl<'p, P: MutMatlabPtr + 'p> MutMatlabClass<P> for Struct<P>

Source§

type AsBorrowed<'a> = Struct<&'a mxArray_tag> where P: 'a

Source§

fn as_borrowed<'a>(&'a self) -> Self::AsBorrowed<'a>

Source§

fn inner_mut(&mut self) -> &mut P

Source§

impl NewEmpty for Struct<MxArray>

Source§

fn new_empty() -> Self

Construct the empty type
Source§

impl OwnedMatlabClass for Struct<MxArray>

Source§

type AsMutable<'a> = Struct<&'a mut mxArray_tag> where Self: 'a

The way this class would be represented if it were a mutable borrow.
Source§

fn as_mutable<'a>(&'a mut self) -> Self::AsMutable<'a>

Create a MutMatlabClass from this owned instance.
Source§

impl<P: PartialEq> PartialEq for Struct<P>

Source§

fn eq(&self, other: &Struct<P>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<P: Copy> Copy for Struct<P>

Source§

impl<P: Eq> Eq for Struct<P>

Source§

impl<P> StructuralPartialEq for Struct<P>

Auto Trait Implementations§

§

impl<P> Freeze for Struct<P>
where P: Freeze,

§

impl<P> RefUnwindSafe for Struct<P>
where P: RefUnwindSafe,

§

impl<P> Send for Struct<P>
where P: Send,

§

impl<P> Sync for Struct<P>
where P: Sync,

§

impl<P> Unpin for Struct<P>
where P: Unpin,

§

impl<P> UnwindSafe for Struct<P>
where P: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.