diff options
-rw-r--r-- | candle-core/src/dtype.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/candle-core/src/dtype.rs b/candle-core/src/dtype.rs index 94ca57d8..1a698a35 100644 --- a/candle-core/src/dtype.rs +++ b/candle-core/src/dtype.rs @@ -23,7 +23,15 @@ pub enum DType { } #[derive(Debug, PartialEq, Eq)] -pub struct DTypeParseError; +pub struct DTypeParseError(String); + +impl std::fmt::Display for DTypeParseError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "cannot parse '{}' as a dtype", self.0) + } +} + +impl std::error::Error for DTypeParseError {} impl std::str::FromStr for DType { type Err = DTypeParseError; @@ -36,7 +44,7 @@ impl std::str::FromStr for DType { "f16" => Ok(Self::F16), "f32" => Ok(Self::F32), "f64" => Ok(Self::F64), - _ => Err(DTypeParseError), + _ => Err(DTypeParseError(s.to_string())), } } } |