randomx_bindings/
error.rs

1use std::error::Error;
2use std::fmt;
3
4#[derive(Debug)]
5pub enum RandomxError {
6    /// Occurs when allocating the RandomX cache fails.
7    ///
8    /// Reasons include:
9    ///  * Memory allocation fails
10    ///  * The JIT flag is set but the current platform does not support it
11    ///  * An invalid or unsupported ARGON2 value is set
12    CacheAllocError,
13
14    /// Occurs when allocating a RandomX dataset fails.
15    ///
16    /// Reasons include:
17    ///  * Memory allocation fails
18    DatasetAllocError,
19
20    /// Occurs when creating a VM fails.
21    ///
22    /// Reasons include:
23    ///  * Scratchpad memory allocation fails
24    ///  * Unsupported flags
25    VmAllocError,
26}
27
28impl fmt::Display for RandomxError {
29    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
30        match *self {
31            RandomxError::CacheAllocError => write!(f, "Failed to allocate cache"),
32            RandomxError::DatasetAllocError => write!(f, "Failed to allocate datataset"),
33            RandomxError::VmAllocError => write!(f, "Failed to create VM"),
34        }
35    }
36}
37
38impl Error for RandomxError {
39    fn description(&self) -> &str {
40        match *self {
41            RandomxError::CacheAllocError => "Failed to allocate cache",
42            RandomxError::DatasetAllocError => "Failed to allocate dataset",
43            RandomxError::VmAllocError => "Failed to create VM",
44        }
45    }
46
47    fn cause(&self) -> Option<&dyn Error> {
48        None
49    }
50}