matrix-rs/src/main.rs
Zhongheng Liu fcf4d05b8a
feat: various fixes
clippy: rm unnecessary borrows
structure: move struct definitions around
tests: add unit test for matrix operations
errors: add custom error types
2025-01-22 20:29:02 +02:00

25 lines
626 B
Rust

use std::{error::Error, io::stdin, str::FromStr};
#[cfg(test)]
mod tests;
use types::{matrix::Matrix, matrix_err::ParseMatrixError};
mod types;
fn handle_input() -> Result<Matrix, ParseMatrixError> {
let input = stdin();
let mut construct_string = String::from("");
loop {
let mut s = "".to_string();
let _ = input.read_line(&mut s);
if s == "exit\n" {
break;
}
construct_string += &s;
}
Matrix::from_str(construct_string.trim_end())
}
fn main() -> Result<(), Box<dyn Error>> {
let m = handle_input()?;
Ok(println!("The matrix is:\n{}", m))
}