Enum mocktave::OctaveType
source · pub enum OctaveType {
Scalar(f64),
ComplexScalar(f64, f64),
Matrix(Vec<Vec<f64>>),
String(String),
CellArray(Vec<Vec<OctaveType>>),
Empty,
Error(String),
}
Expand description
Possible types that can be returned from Octave through this library.
Variants§
Scalar(f64)
A scalar value, accounting for both integers and floats. The underlying type is f64
.
ComplexScalar(f64, f64)
A complex scalar value, accounting for both integers and floats. The underlying type is a
pair of f64
s.
Matrix(Vec<Vec<f64>>)
A numerical matrix, accounting 2 dimensional matrices of scalars. The underlying type is
Vec<Vec<f64>>
.
String(String)
A string value, accounting for both single and double quote strings. The underlying type is
String
.
CellArray(Vec<Vec<OctaveType>>)
A cell array, which is essentially a matrix of non-numeric types. The underlying type is
Vec<Vec<OctaveType>>
.
Empty
Something a value might be empty. This is mostly for the implementation of Default
.
Error(String)
Sometimes a value might be an error too.
Implementations§
source§impl OctaveType
impl OctaveType
sourcepub fn try_into_f64(self) -> Result<f64, OctaveTryIntoError>
pub fn try_into_f64(self) -> Result<f64, OctaveTryIntoError>
Unwrap a scalar octave type into f64
let x: f64 = mocktave::OctaveType::Scalar(0.0).try_into_f64().unwrap();
sourcepub fn try_into_string(self) -> Result<String, OctaveTryIntoError>
pub fn try_into_string(self) -> Result<String, OctaveTryIntoError>
Unwrap a string octave type into String
let x: String = mocktave::OctaveType::String("0.0".to_string()).try_into_string().unwrap();
sourcepub fn try_into_vec_f64(self) -> Result<Vec<Vec<f64>>, OctaveTryIntoError>
pub fn try_into_vec_f64(self) -> Result<Vec<Vec<f64>>, OctaveTryIntoError>
Unwrap a matrix octave type into Vec<Vec<f64>>
let x: Vec<Vec<f64>> = mocktave::OctaveType::Matrix(vec![vec![0.0_f64;2];2]).try_into_vec_f64().unwrap();
sourcepub fn try_into_vec_octave_type(
self
) -> Result<Vec<Vec<OctaveType>>, OctaveTryIntoError>
pub fn try_into_vec_octave_type( self ) -> Result<Vec<Vec<OctaveType>>, OctaveTryIntoError>
Unwrap a cell array octave type into Vec<Vec<OctaveType>>
let x: Vec<Vec<mocktave::OctaveType>> = mocktave::OctaveType::CellArray(vec![vec![mocktave::OctaveType::Scalar(1.0)]]).try_into_vec_octave_type().unwrap();
sourcepub fn try_into_empty(self) -> Result<(), OctaveTryIntoError>
pub fn try_into_empty(self) -> Result<(), OctaveTryIntoError>
Unwrap an Empty octave type into ()
let x: () = mocktave::OctaveType::default().try_into_empty().unwrap();
Trait Implementations§
source§impl Clone for OctaveType
impl Clone for OctaveType
source§fn clone(&self) -> OctaveType
fn clone(&self) -> OctaveType
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for OctaveType
impl Debug for OctaveType
source§impl Default for OctaveType
impl Default for OctaveType
Implementation of the Default trait
use mocktave::OctaveType;
let dflt = OctaveType::default();
assert_eq!(dflt, OctaveType::Empty);
source§impl Display for OctaveType
impl Display for OctaveType
Implementation of the Display trait
source§impl From<()> for OctaveType
impl From<()> for OctaveType
Convert an ()
into an OctaveType::Empty
use mocktave::OctaveType;
let x: OctaveType = ().into();
assert_eq!(x, OctaveType::Empty)
source§impl From<OctaveType> for ()
impl From<OctaveType> for ()
Convert an OctaveType::Empty
into an ‘()’
use mocktave::OctaveType;
let x: () = OctaveType::Empty.into();
assert_eq!((), x);
source§fn from(_value: OctaveType) -> Self
fn from(_value: OctaveType) -> Self
source§impl From<OctaveType> for String
impl From<OctaveType> for String
Convert an OctaveType::String
into a proper rust String
use mocktave::OctaveType;
let x: String = OctaveType::String("asdf".to_string()).into();
assert_eq!(x, "asdf".to_string());
source§fn from(value: OctaveType) -> Self
fn from(value: OctaveType) -> Self
source§impl<T: Primitive + From<OctaveType>> From<OctaveType> for Vec<T>
impl<T: Primitive + From<OctaveType>> From<OctaveType> for Vec<T>
Convert an OctaveType::Matrix
into a Vec<T>
use mocktave::OctaveType;
let x: Vec<usize> = OctaveType::Matrix(vec![vec![0.0; 5]; 1]).into();
assert_eq!(x, vec![0_usize; 5])
source§fn from(value: OctaveType) -> Self
fn from(value: OctaveType) -> Self
source§impl From<OctaveType> for Vec<Vec<OctaveType>>
impl From<OctaveType> for Vec<Vec<OctaveType>>
Convert an OctaveType::CellArray
into Vec<Vec<OctaveType>>
use mocktave::OctaveType;
let x: Vec<Vec<OctaveType>> = OctaveType::CellArray(vec![vec![OctaveType::default(); 1]]).into();
assert_eq!(x, vec![vec![OctaveType::default(); 1]]);
source§fn from(value: OctaveType) -> Self
fn from(value: OctaveType) -> Self
source§impl<T: From<OctaveType> + Primitive> From<OctaveType> for Vec<Vec<T>>
impl<T: From<OctaveType> + Primitive> From<OctaveType> for Vec<Vec<T>>
Convert an OctaveType::Matrix
into a Vec<Vec<T>>
use mocktave::OctaveType;
let x: Vec<Vec<usize>> = OctaveType::Matrix(vec![vec![0.0; 2]; 2]).into();
assert_eq!(x, vec![vec![0_usize; 2]; 2])
use mocktave::{OctaveType, wrap};
let ones = wrap("ones".into());
let mat: OctaveType = ones([3]);
let x: Vec<Vec<usize>> = mat.into();
assert_eq!(x, vec![vec![1_usize; 3]; 3])
source§fn from(value: OctaveType) -> Self
fn from(value: OctaveType) -> Self
source§impl From<OctaveType> for f32
impl From<OctaveType> for f32
Convert an OctaveType::Scalar
into an ‘f32’
use mocktave::OctaveType;
let x: f32 = OctaveType::Scalar(1.0).into();
assert_eq!(x, 1.0_f32);
source§fn from(value: OctaveType) -> Self
fn from(value: OctaveType) -> Self
source§impl From<OctaveType> for f64
impl From<OctaveType> for f64
Convert an OctaveType::Scalar
into an ‘f64’
use mocktave::OctaveType;
let x: f64 = OctaveType::Scalar(1.0).into();
assert_eq!(x, 1.0_f64);
source§fn from(value: OctaveType) -> Self
fn from(value: OctaveType) -> Self
source§impl From<OctaveType> for i128
impl From<OctaveType> for i128
Convert an OctaveType::Scalar
into an ‘i128’
use mocktave::OctaveType;
let x: i128 = OctaveType::Scalar(1.0).into();
assert_eq!(x, 1_i128);
source§fn from(value: OctaveType) -> Self
fn from(value: OctaveType) -> Self
source§impl From<OctaveType> for i16
impl From<OctaveType> for i16
Convert an OctaveType::Scalar
into an ‘i16’
use mocktave::OctaveType;
let x: i16 = OctaveType::Scalar(1.0).into();
assert_eq!(x, 1_i16);
source§fn from(value: OctaveType) -> Self
fn from(value: OctaveType) -> Self
source§impl From<OctaveType> for i32
impl From<OctaveType> for i32
Convert an OctaveType::Scalar
into an ‘i32’
use mocktave::OctaveType;
let x: i32 = OctaveType::Scalar(1.0).into();
assert_eq!(x, 1_i32);
source§fn from(value: OctaveType) -> Self
fn from(value: OctaveType) -> Self
source§impl From<OctaveType> for i64
impl From<OctaveType> for i64
Convert an OctaveType::Scalar
into an ‘i64’
use mocktave::OctaveType;
let x: i64 = OctaveType::Scalar(1.0).into();
assert_eq!(x, 1_i64);
source§fn from(value: OctaveType) -> Self
fn from(value: OctaveType) -> Self
source§impl From<OctaveType> for i8
impl From<OctaveType> for i8
Convert an OctaveType::Scalar
into an ‘i8’
use mocktave::OctaveType;
let x: i8 = OctaveType::Scalar(1.0).into();
assert_eq!(x, 1_i8);
source§fn from(value: OctaveType) -> Self
fn from(value: OctaveType) -> Self
source§impl From<OctaveType> for isize
impl From<OctaveType> for isize
Convert an OctaveType::Scalar
into a u64
use mocktave::OctaveType;
let x: isize = OctaveType::Scalar(1.0).into();
assert_eq!(x, 1_isize);
source§fn from(value: OctaveType) -> Self
fn from(value: OctaveType) -> Self
source§impl From<OctaveType> for u128
impl From<OctaveType> for u128
Convert an OctaveType::Scalar
into a u128
use mocktave::OctaveType;
let x: u128 = OctaveType::Scalar(1.0).into();
assert_eq!(x, 1_u128);
source§fn from(value: OctaveType) -> Self
fn from(value: OctaveType) -> Self
source§impl From<OctaveType> for u16
impl From<OctaveType> for u16
Convert an OctaveType::Scalar
into a ‘u16’
use mocktave::OctaveType;
let x: u16 = OctaveType::Scalar(1.0).into();
assert_eq!(x, 1_u16);
source§fn from(value: OctaveType) -> Self
fn from(value: OctaveType) -> Self
source§impl From<OctaveType> for u32
impl From<OctaveType> for u32
Convert an OctaveType::Scalar
into a ‘u32’
use mocktave::OctaveType;
let x: u32 = OctaveType::Scalar(1.0).into();
assert_eq!(x, 1_u32);
source§fn from(value: OctaveType) -> Self
fn from(value: OctaveType) -> Self
source§impl From<OctaveType> for u64
impl From<OctaveType> for u64
Convert an OctaveType::Scalar
into a ‘u64’
use mocktave::OctaveType;
let x: u64 = OctaveType::Scalar(1.0).into();
assert_eq!(x, 1_u64);
source§fn from(value: OctaveType) -> Self
fn from(value: OctaveType) -> Self
source§impl From<OctaveType> for u8
impl From<OctaveType> for u8
Convert an OctaveType::Scalar
into a ‘u8’
use mocktave::OctaveType;
let x: u8 = OctaveType::Scalar(1.0).into();
assert_eq!(x, 1_u8);
source§fn from(value: OctaveType) -> Self
fn from(value: OctaveType) -> Self
source§impl From<OctaveType> for usize
impl From<OctaveType> for usize
Convert an OctaveType::Scalar
into a ‘usize’
use mocktave::OctaveType;
let x: usize = OctaveType::Scalar(1.0).into();
assert_eq!(x, 1_usize);
source§fn from(value: OctaveType) -> Self
fn from(value: OctaveType) -> Self
source§impl<T: Into<OctaveType> + Primitive> From<Vec<T, Global>> for OctaveType
impl<T: Into<OctaveType> + Primitive> From<Vec<T, Global>> for OctaveType
Convert a Vec<T>
into an OctaveType::Matrix
use mocktave::OctaveType;
let x: OctaveType = vec![0.0; 5].into();
assert_eq!(x, OctaveType::Matrix(vec![vec![0.0; 5]; 1]))
source§impl<T: Into<OctaveType> + Primitive> From<Vec<Vec<T, Global>, Global>> for OctaveType
impl<T: Into<OctaveType> + Primitive> From<Vec<Vec<T, Global>, Global>> for OctaveType
Convert a Vec<Vec<T>>
into an OctaveType::Matrix
use mocktave::OctaveType;
let x: OctaveType = vec![vec![0.0; 2]; 2].into();
assert_eq!(x, OctaveType::Matrix(vec![vec![0.0; 2]; 2]))
source§impl From<f32> for OctaveType
impl From<f32> for OctaveType
Convert an f32
into an OctaveType::Scalar
use mocktave::OctaveType;
let x: OctaveType = 1.0_f32.into();
assert_eq!(x, OctaveType::Scalar(1.0))
source§impl From<f64> for OctaveType
impl From<f64> for OctaveType
Convert an f64
into an OctaveType::Scalar
use mocktave::OctaveType;
let x: OctaveType = 1.0_f64.into();
assert_eq!(x, OctaveType::Scalar(1.0))
source§impl From<i128> for OctaveType
impl From<i128> for OctaveType
Convert a i128
into an OctaveType::Scalar
use mocktave::OctaveType;
let x: OctaveType = 1_i128.into();
assert_eq!(x, OctaveType::Scalar(1.0))
source§impl From<i16> for OctaveType
impl From<i16> for OctaveType
Convert a i16
into an OctaveType::Scalar
use mocktave::OctaveType;
let x: OctaveType = 1_i16.into();
assert_eq!(x, OctaveType::Scalar(1.0))
source§impl From<i32> for OctaveType
impl From<i32> for OctaveType
Convert a i32
into an OctaveType::Scalar
use mocktave::OctaveType;
let x: OctaveType = 1_i32.into();
assert_eq!(x, OctaveType::Scalar(1.0))
source§impl From<i64> for OctaveType
impl From<i64> for OctaveType
Convert a i64
into an OctaveType::Scalar
use mocktave::OctaveType;
let x: OctaveType = 1_i64.into();
assert_eq!(x, OctaveType::Scalar(1.0))
source§impl From<i8> for OctaveType
impl From<i8> for OctaveType
Convert a i8
into an OctaveType::Scalar
use mocktave::OctaveType;
let x: OctaveType = 1_i8.into();
assert_eq!(x, OctaveType::Scalar(1.0))
source§impl From<isize> for OctaveType
impl From<isize> for OctaveType
Convert a isize
into an OctaveType::Scalar
use mocktave::OctaveType;
let x: OctaveType = 1_isize.into();
assert_eq!(x, OctaveType::Scalar(1.0))
source§impl From<u128> for OctaveType
impl From<u128> for OctaveType
Convert a u128
into an OctaveType::Scalar
use mocktave::OctaveType;
let x: OctaveType = 1_u128.into();
assert_eq!(x, OctaveType::Scalar(1.0))
source§impl From<u16> for OctaveType
impl From<u16> for OctaveType
Convert a u16
into an OctaveType::Scalar
use mocktave::OctaveType;
let x: OctaveType = 1_u16.into();
assert_eq!(x, OctaveType::Scalar(1.0))
source§impl From<u32> for OctaveType
impl From<u32> for OctaveType
Convert a u32
into an OctaveType::Scalar
use mocktave::OctaveType;
let x: OctaveType = 1_u32.into();
assert_eq!(x, OctaveType::Scalar(1.0))
source§impl From<u64> for OctaveType
impl From<u64> for OctaveType
Convert a u64
into an OctaveType::Scalar
use mocktave::OctaveType;
let x: OctaveType = 1_u64.into();
assert_eq!(x, OctaveType::Scalar(1.0))
source§impl From<u8> for OctaveType
impl From<u8> for OctaveType
Convert a u8
into an OctaveType::Scalar
use mocktave::OctaveType;
let x: OctaveType = 1_u8.into();
assert_eq!(x, OctaveType::Scalar(1.0))
source§impl From<usize> for OctaveType
impl From<usize> for OctaveType
Convert a usize
into an OctaveType::Scalar
use mocktave::OctaveType;
let x: OctaveType = 1_usize.into();
assert_eq!(x, OctaveType::Scalar(1.0))
source§impl PartialEq<OctaveType> for OctaveType
impl PartialEq<OctaveType> for OctaveType
source§fn eq(&self, other: &OctaveType) -> bool
fn eq(&self, other: &OctaveType) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<OctaveType> for OctaveType
impl PartialOrd<OctaveType> for OctaveType
source§fn partial_cmp(&self, other: &OctaveType) -> Option<Ordering>
fn partial_cmp(&self, other: &OctaveType) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl StructuralPartialEq for OctaveType
Auto Trait Implementations§
impl RefUnwindSafe for OctaveType
impl Send for OctaveType
impl Sync for OctaveType
impl Unpin for OctaveType
impl UnwindSafe for OctaveType
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request