Compare commits

..

2 Commits

Author SHA1 Message Date
725ca99712 addition: error implementation 2026-04-29 17:57:30 -06:00
2494c237d7 cargo: took out num-traits dependency 2026-04-29 17:54:33 -06:00
3 changed files with 41 additions and 18 deletions

16
Cargo.lock generated
View File

@@ -2,12 +2,6 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 4 version = 4
[[package]]
name = "autocfg"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
[[package]] [[package]]
name = "fractions" name = "fractions"
version = "0.1.0" version = "0.1.0"
@@ -18,14 +12,4 @@ name = "matrix"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"fractions", "fractions",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
dependencies = [
"autocfg",
] ]

View File

@@ -4,5 +4,4 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
num-traits = "0.2.19"
fractions = {git = "https://laentropia-homelab.tail7368da.ts.net/laentropia/Rusty-Fractions.git", branch= "main" } fractions = {git = "https://laentropia-homelab.tail7368da.ts.net/laentropia/Rusty-Fractions.git", branch= "main" }

View File

@@ -1,6 +1,7 @@
use fractions::{Fraction, FractionError}; use fractions::{Fraction, FractionError};
use std::cmp::min; use std::cmp::min;
use std::fmt::{Debug, Display}; use std::error::Error;
use std::fmt::{self, Debug, Display};
use std::ops::Add; use std::ops::Add;
use std::ops::Mul; use std::ops::Mul;
use std::ops::Sub; use std::ops::Sub;
@@ -27,6 +28,45 @@ impl From<FractionError> for MatrixError {
} }
} }
impl fmt::Display for MatrixError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
MatrixError::IndexOutOfRange => write!(f, "Index out of range"),
MatrixError::RowOutOfRange => write!(f, "Row index out of range"),
MatrixError::ColumnOutOfRange => write!(f, "Column index out of range"),
MatrixError::NotSquared => write!(f, "Matrix must be square"),
MatrixError::InvalidDataSize => write!(f, "Invalid data size for matrix"),
MatrixError::InvalidSizeForAdd => {
write!(f, "Matrices must have same dimensions for addition")
}
MatrixError::InvalidSizeForSub => {
write!(f, "Matrices must have same dimensions for subtraction")
}
MatrixError::InvalidSizeForMul => {
write!(f, "Invalid matrix dimensions for multiplication")
}
MatrixError::ZeroSize => write!(f, "Matrix cannot have zero rows or columns"),
MatrixError::FailedGauss => {
write!(f, "Gaussian elimination failed (possibly singular matrix)")
}
MatrixError::FailedGaussJordan => write!(
f,
"Gauss-Jordan elimination failed (possibly singular matrix)"
),
MatrixError::FractionError(err) => write!(f, "Fraction error: {}", err),
}
}
}
impl Error for MatrixError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
MatrixError::FractionError(err) => Some(err),
_ => None,
}
}
}
#[derive(PartialEq, Eq, Debug, Clone)] #[derive(PartialEq, Eq, Debug, Clone)]
pub struct Matrix { pub struct Matrix {
rows: usize, rows: usize,