diff options
author | Simon THOBY <git@nightmared.fr> | 2021-10-23 23:02:22 +0200 |
---|---|---|
committer | Simon THOBY <git@nightmared.fr> | 2021-11-02 22:18:12 +0100 |
commit | 7f7b2c3af6e6f7a596a85ada823408bdd0b02118 (patch) | |
tree | 48908226b5252d0e86758fe36d05c1491f080ac1 /rustables/src/expr/wrapper.rs | |
parent | 82ebb702c1358ac4af40c7ee43efa6f364fa6d50 (diff) |
replace Optionnals by Results for a better error propagation when deserializing expressions
Diffstat (limited to 'rustables/src/expr/wrapper.rs')
-rw-r--r-- | rustables/src/expr/wrapper.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/rustables/src/expr/wrapper.rs b/rustables/src/expr/wrapper.rs index b9b90b3..5162c21 100644 --- a/rustables/src/expr/wrapper.rs +++ b/rustables/src/expr/wrapper.rs @@ -3,6 +3,7 @@ use std::ffi::CString; use std::fmt::Debug; use std::rc::Rc; +use super::DeserializationError; use super::Expression; use crate::Rule; use rustables_sys as sys; @@ -48,15 +49,14 @@ impl ExpressionWrapper { } } - /// Attempt to decode the expression as the type T, returning None if such - /// conversion is not possible or failed. - pub fn decode_expr<T: Expression>(&self) -> Option<T> { + /// Attempt to decode the expression as the type T. + pub fn decode_expr<T: Expression>(&self) -> Result<T, DeserializationError> { if let Some(kind) = self.get_kind() { let raw_name = unsafe { CStr::from_ptr(T::get_raw_name()) }; if kind == raw_name { return T::from_expr(self.expr); } } - None + Err(DeserializationError::InvalidExpressionKind) } } |