1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use alloc::string::String;
use thiserror::Error;
/// Errors produced by jantu operations.
///
/// # Examples
///
/// ```
/// use jantu::JantuError;
///
/// let err = JantuError::InvalidDrive("negative hunger".into());
/// assert!(err.to_string().contains("negative hunger"));
/// ```
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum JantuError {
/// An invalid or unrecognized behavior was requested.
#[error("invalid behavior: {0}")]
InvalidBehavior(String),
/// A drive value was out of range or otherwise invalid.
#[error("invalid drive: {0}")]
InvalidDrive(String),
/// A social state transition was invalid.
#[error("invalid social state: {0}")]
InvalidSocialState(String),
/// A numerical computation produced an invalid result.
#[error("computation error: {0}")]
ComputationError(String),
}
/// Convenience alias for `core::result::Result<T, JantuError>`.
pub type Result<T> = core::result::Result<T, JantuError>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn error_display() {
let e = JantuError::InvalidBehavior("unknown instinct".into());
assert!(e.to_string().contains("unknown instinct"));
}
}