aboutsummaryrefslogtreecommitdiff
path: root/rustables/src/expr/wrapper.rs
diff options
context:
space:
mode:
authorSimon THOBY <git@nightmared.fr>2021-10-23 23:02:22 +0200
committerSimon THOBY <git@nightmared.fr>2021-11-02 22:18:12 +0100
commit7f7b2c3af6e6f7a596a85ada823408bdd0b02118 (patch)
tree48908226b5252d0e86758fe36d05c1491f080ac1 /rustables/src/expr/wrapper.rs
parent82ebb702c1358ac4af40c7ee43efa6f364fa6d50 (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.rs8
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)
}
}