concision_neural/
error.rs1#[cfg(feature = "alloc")]
11use alloc::{boxed::Box, string::String};
12
13pub type NeuralResult<T> = core::result::Result<T, NeuralError>;
16
17#[derive(Debug, scsys::VariantConstructors, thiserror::Error)]
25#[non_exhaustive]
26pub enum NeuralError {
27 #[error("Invalid Batch Size")]
28 InvalidBatchSize,
29 #[error("Invalid Input Shape")]
30 InvalidInputShape,
31 #[error("Invalid Output Shape")]
32 InvalidOutputShape,
33 #[error(transparent)]
34 TrainingError(#[from] TrainingError),
35 #[error(transparent)]
36 CoreError(#[from] concision_core::error::Error),
37 #[cfg(feature = "alloc")]
38 #[error("Parameter Error")]
39 ParameterError(String),
40}
41
42#[derive(Debug, scsys::VariantConstructors, thiserror::Error)]
43pub enum TrainingError {
44 #[error("Invalid Training Data")]
45 InvalidTrainingData,
46 #[error("Training Failed")]
47 TrainingFailed,
48}
49
50impl From<NeuralError> for concision_core::error::Error {
51 fn from(err: NeuralError) -> Self {
52 match err {
53 NeuralError::CoreError(e) => e,
54 _ => concision_core::error::Error::box_error(err),
55 }
56 }
57}
58
59#[cfg(feature = "alloc")]
60impl From<Box<dyn core::error::Error + Send + Sync>> for NeuralError {
61 fn from(err: Box<dyn core::error::Error + Send + Sync>) -> Self {
62 cnc::Error::BoxError(err).into()
63 }
64}
65#[cfg(feature = "alloc")]
66impl From<String> for NeuralError {
67 fn from(err: String) -> Self {
68 cnc::Error::unknown(err).into()
69 }
70}
71
72#[cfg(feature = "alloc")]
73impl From<&str> for NeuralError {
74 fn from(err: &str) -> Self {
75 cnc::Error::unknown(err).into()
76 }
77}