concision_init/
error.rs

1/*
2    appellation: error <module>
3    authors: @FL03
4*/
5/// this module defines the error type, [`InitError`], used for various initialization errors
6/// that one may encounter within the library.
7#[cfg(feature = "alloc")]
8use alloc::string::String;
9use rand_distr::NormalError;
10use rand_distr::uniform::Error as UniformError;
11#[allow(dead_code)]
12/// a private type alias for a [`Result`](core::result::Result) type that is used throughout
13/// the library using an [`InitError`](InitError) as the error type.
14pub(crate) type Result<T> = core::result::Result<T, InitError>;
15
16#[derive(Debug, thiserror::Error)]
17pub enum InitError {
18    #[cfg(feature = "alloc")]
19    #[error("Failed to initialize with the given distribution: {0}")]
20    DistributionError(String),
21    #[cfg(feature = "rand")]
22    #[error("[NormalError] {0}")]
23    NormalError(NormalError),
24    #[error(transparent)]
25    #[cfg(feature = "rand")]
26    UniformError(#[from] UniformError),
27}
28
29#[cfg(feature = "rand")]
30impl From<NormalError> for InitError {
31    fn from(err: NormalError) -> Self {
32        InitError::NormalError(err)
33    }
34}