Skip to main content

matrix_rain/
error.rs

1//! Error types returned by the builder and config validation.
2
3use alloc::string::String;
4
5use thiserror::Error;
6
7/// Errors produced by [`MatrixConfigBuilder::build`](crate::MatrixConfigBuilder::build)
8/// and related validation routines.
9#[derive(Debug, Error)]
10pub enum MatrixError {
11    /// A configuration value failed its invariant check (e.g. `fps < 1`,
12    /// non-finite `speed`, `density` outside `[0.0, 1.0]`, `min_trail > max_trail`).
13    /// The string carries a human-readable description of which field and why.
14    #[error("invalid configuration: {0}")]
15    InvalidConfig(/// Reason the config was rejected.
16        String),
17
18    /// The configured [`CharSet`](crate::CharSet) resolves to zero glyphs.
19    /// Only [`CharSet::Custom`](crate::CharSet::Custom) with an empty `Vec`
20    /// can hit this — the built-in variants always resolve to non-empty
21    /// lists.
22    #[error("empty character set")]
23    EmptyCharset,
24}
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29
30    #[test]
31    fn invalid_config_renders_message() {
32        let e = MatrixError::InvalidConfig("fps must be >= 1".into());
33        assert_eq!(e.to_string(), "invalid configuration: fps must be >= 1");
34    }
35
36    #[test]
37    fn empty_charset_renders_message() {
38        assert_eq!(MatrixError::EmptyCharset.to_string(), "empty character set");
39    }
40}