rust_mlp/error.rs
1//! Error and `Result` types.
2//!
3//! This crate uses a split error-handling policy:
4//! - Configuration/data validation at the API boundary returns `Result`.
5//! - Low-level hot-path methods (e.g. per-sample forward/backward) panic on misuse
6//! (shape mismatches) via `assert!` / `assert_eq!`.
7
8use std::fmt;
9
10#[derive(Debug, Clone)]
11/// Errors returned by fallible constructors and high-level APIs.
12pub enum Error {
13 /// The provided dataset/inputs/targets are invalid.
14 InvalidData(String),
15 /// The provided configuration is invalid (e.g. zero-sized layer, non-finite lr).
16 InvalidConfig(String),
17}
18
19/// Convenience alias used throughout the crate.
20pub type Result<T> = std::result::Result<T, Error>;
21
22impl fmt::Display for Error {
23 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24 match self {
25 Error::InvalidData(msg) => write!(f, "invalid data: {msg}"),
26 Error::InvalidConfig(msg) => write!(f, "invalid config: {msg}"),
27 }
28 }
29}
30
31impl std::error::Error for Error {}