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

§

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

source

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();
source

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();
source

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();
source

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();
source

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

source§

fn clone(&self) -> OctaveType

Returns a copy 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 Debug for OctaveType

source§

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

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

impl Default for OctaveType

Implementation of the Default trait

use mocktave::OctaveType;
let dflt = OctaveType::default();
assert_eq!(dflt, OctaveType::Empty);
source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Display for OctaveType

Implementation of the Display trait

source§

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

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

impl From<()> for OctaveType

Convert an () into an OctaveType::Empty

use mocktave::OctaveType;
let x: OctaveType = ().into();
assert_eq!(x, OctaveType::Empty)
source§

fn from(_value: ()) -> Self

Converts to this type from the input type.
source§

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

Converts to this type from the input type.
source§

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

Converts to this type from the input type.
source§

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

Converts to this type from the input type.
source§

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

Converts to this type from the input type.
source§

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

Converts to this type from the input type.
source§

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

Converts to this type from the input type.
source§

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

Converts to this type from the input type.
source§

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

Converts to this type from the input type.
source§

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

Converts to this type from the input type.
source§

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

Converts to this type from the input type.
source§

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

Converts to this type from the input type.
source§

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

Converts to this type from the input type.
source§

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

Converts to this type from the input type.
source§

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

Converts to this type from the input type.
source§

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

Converts to this type from the input type.
source§

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

Converts to this type from the input type.
source§

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

Converts to this type from the input type.
source§

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

Converts to this type from the input type.
source§

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

Converts to this type from the input type.
source§

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§

fn from(value: Vec<T>) -> Self

Converts to this type from the input type.
source§

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§

fn from(value: Vec<Vec<T>>) -> Self

Converts to this type from the input type.
source§

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§

fn from(value: f32) -> Self

Converts to this type from the input type.
source§

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§

fn from(value: f64) -> Self

Converts to this type from the input type.
source§

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§

fn from(value: i128) -> Self

Converts to this type from the input type.
source§

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§

fn from(value: i16) -> Self

Converts to this type from the input type.
source§

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§

fn from(value: i32) -> Self

Converts to this type from the input type.
source§

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§

fn from(value: i64) -> Self

Converts to this type from the input type.
source§

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§

fn from(value: i8) -> Self

Converts to this type from the input type.
source§

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§

fn from(value: isize) -> Self

Converts to this type from the input type.
source§

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§

fn from(value: u128) -> Self

Converts to this type from the input type.
source§

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§

fn from(value: u16) -> Self

Converts to this type from the input type.
source§

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§

fn from(value: u32) -> Self

Converts to this type from the input type.
source§

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§

fn from(value: u64) -> Self

Converts to this type from the input type.
source§

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§

fn from(value: u8) -> Self

Converts to this type from the input type.
source§

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§

fn from(value: usize) -> Self

Converts to this type from the input type.
source§

impl PartialEq<OctaveType> for OctaveType

source§

fn eq(&self, other: &OctaveType) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<OctaveType> for OctaveType

source§

fn partial_cmp(&self, other: &OctaveType) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl StructuralPartialEq for OctaveType

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for Twhere T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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<T> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> ToOwned for Twhere T: Clone,

§

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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more