[librsvg] error.rs: Implement From<ParseError> for AttributeError
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] error.rs: Implement From<ParseError> for AttributeError
- Date: Thu, 16 Mar 2017 05:16:30 +0000 (UTC)
commit bbea658427ff3d3b693fb46f07ea17d4b70c0618
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Mar 15 20:42:32 2017 -0600
error.rs: Implement From<ParseError> for AttributeError
This lets us convert a low-level ParseError implicitly to a higher-level
AttributeError.
rust/src/error.rs | 27 +++++++++++++++++++++++++++
1 files changed, 27 insertions(+), 0 deletions(-)
---
diff --git a/rust/src/error.rs b/rust/src/error.rs
index ea07cd1..101f2b7 100644
--- a/rust/src/error.rs
+++ b/rust/src/error.rs
@@ -59,3 +59,30 @@ impl fmt::Display for NodeError {
}
}
+impl From<ParseError> for AttributeError {
+ fn from (pe: ParseError) -> AttributeError {
+ AttributeError::Parse (pe)
+ }
+}
+
+pub fn is_parse_error<T> (r: &Result<T, AttributeError>) -> bool {
+ if r.is_err () {
+ match r.unwrap_err () {
+ AttributeError::Parse (_) => true,
+ _ => false
+ }
+ } else {
+ false
+ }
+}
+
+pub fn is_value_error<T> (r: &Result<T, AttributeError>) -> bool {
+ if r.is_err () {
+ match r.unwrap_err () {
+ AttributeError::Value (_) => true,
+ _ => false
+ }
+ } else {
+ false
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]