I'm currently working on a simple project to get myself familiar with Rust. I don't have much systems programming experience but I'm hoping to learn!
I'm trying to create a Matrix struct but I'm finding it hard to figure out how I should store the data. I feel like I should be able to use an array. The size of the matrix must be defined on construction and so I would hope I can store the array on the stack.
Right now my code looks like this:
use std::ops::Mul;
use std::ops::Add;
use std::ops::Div;
struct Matrix {
cols: i32,
rows: i32,
// Of course this doesn't work!
data: [f32; ..cols*rows]
}
// Below here are a bunch of stub methods.
impl Mul<f32> for Matrix {
type Output = Matrix;
fn mul(self, m: f32) -> Matrix {
return self;
}
}
impl Mul<Matrix> for Matrix {
type Output = Matrix;
fn mul(self, m: Matrix) -> Matrix {
// Will use Strassen algorithm if large, traditional otherwise
return self;
}
}
impl Add<Matrix> for Matrix {
type Output = Matrix;
fn add(self, m: Matrix) -> Matrix {
return self;
}
}
impl Div<f32> for Matrix {
type Output = Matrix;
fn div(self, f: f32) -> Matrix {
return self;
}
}