#[cfg(feature = "matlab800")]
pub mod backend {
#![doc = include_str!("backend_installation.md")]
#[cfg(any(feature="matlab700", feature="octave"))]
compile_error!("Pick only one backend");
extern crate rustmex_matlab800;
}
#[cfg(feature = "matlab700")]
pub mod backend {
#![doc = include_str!("backend_installation.md")]
#[cfg(any(feature="matlab800", feature="octave"))]
compile_error!("Pick only one backend");
extern crate rustmex_matlab700;
}
#[cfg(feature = "octave")]
pub mod backend {
#![doc = include_str!("backend_installation.md")]
#[cfg(any(feature="matlab700", feature="matlab800"))]
compile_error!("Pick only one backend");
extern crate rustmex_octave;
}
#[cfg(all(doc, not(any(feature="matlab800", feature="matlab700", feature="octave"))))]
pub mod backend {
#![doc = include_str!("backend_installation.md")]
}
pub mod convert;
pub mod message;
pub mod function;
pub mod workspace;
pub mod alloc;
pub mod structs;
pub mod index;
pub mod objects;
pub mod cell;
pub mod numeric;
pub mod char;
pub use rustmex_core::convert::{FromMatlabError};
pub use ::num_complex::Complex;
pub use message::{MexMessage, Error, Missing};
pub use rustmex_core::{mxArray, pointers::MxArray};
pub use rustmex_core::{
MatlabClass,
MutMatlabClass,
NewEmpty,
OwnedMatlabClass,
TakeData,
};
pub type Lhs<'mex> = &'mex mut [Option<MxArray>];
pub type Rhs<'mex, 'matlab> = &'mex [&'matlab mxArray];
#[cfg(feature = "entrypoint")]
pub use rustmex_entrypoint::entrypoint;
pub type Result<T> = std::result::Result<T, message::Error>;
pub mod prelude {
pub use super::{
Lhs, Rhs, LhsAns,
Missing,
};
pub use ::rustmex_core::{mxArray, pointers::MxArray};
}
use std::fmt::Display;
pub fn warning<Id, Msg>(id: Id, msg: Msg) -> ()
where
Id: AsRef<str>,
Msg: Display
{
message::warning(&message::AdHoc(id, msg))
}
#[macro_export]
macro_rules! assert {
($condition:expr, $id:expr, $msg:expr) => {
::rustmex::error_on!(!$condition, $id, $msg);
}
}
#[macro_export]
macro_rules! error_on {
($cond:expr, $id:expr, $msg:expr) => {
if $cond {
::rustmex::error!($id, $msg);
}
}
}
#[macro_export]
macro_rules! error {
($id:expr, $msg:expr) => {
return Err(::rustmex::message::AdHoc($id, $msg).into());
}
}
#[repr(transparent)]
#[derive(Debug)]
pub struct LhsAns<'mex>(&'mex mut [Option<MxArray>]);
impl<'mex> LhsAns<'mex> {
pub fn space(&self) -> usize {
self.0.len().max(1)
}
pub fn nlhs(&self) -> usize {
self.0.len()
}
fn ans_or_lhs(&self) -> Lhs<'mex> {
use ::std::slice::from_raw_parts_mut;
let len = self.space();
let lhs = &self.0;
let ptr = lhs.as_ptr();
unsafe { from_raw_parts_mut(ptr as *mut _, len as usize) }
}
#[doc(hidden)]
pub unsafe fn new(slice: Lhs<'mex>) -> Self {
Self(slice)
}
pub fn lhs(&self) -> &'_ [Option<MxArray>] {
&*self.0
}
pub fn lhs_mut(&mut self) -> Lhs<'_> {
&mut *self.0
}
pub fn ans(&self) -> &'_ Option<MxArray> {
use core::ops::Deref;
let ans = self.deref().first();
unsafe { ans.unwrap_unchecked() }
}
pub fn ans_mut(&mut self) -> &'_ mut Option<MxArray> {
use core::ops::DerefMut;
let ans = self.deref_mut().first_mut();
unsafe { ans.unwrap_unchecked() }
}
}
impl<'mex> core::ops::Deref for LhsAns<'mex> {
type Target = [Option<MxArray>];
fn deref(&self) -> &Self::Target {
let lhs = self.ans_or_lhs();
&*lhs
}
}
impl<'mex> core::ops::DerefMut for LhsAns<'mex> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.ans_or_lhs()
}
}