Browse Source

revision: make EvalError impl Error (#2768)

Miles Murgaw 10 tháng trước cách đây
mục cha
commit
0acfe37398
1 tập tin đã thay đổi với 15 bổ sung0 xóa
  1. 15 0
      packages/html/src/document/eval.rs

+ 15 - 0
packages/html/src/document/eval.rs

@@ -3,6 +3,8 @@
 
 use dioxus_core::prelude::*;
 use generational_box::GenerationalBox;
+use std::error::Error;
+use std::fmt::Display;
 use std::future::{poll_fn, Future, IntoFuture};
 use std::pin::Pin;
 use std::rc::Rc;
@@ -117,3 +119,16 @@ pub enum EvalError {
     /// Represents an error communicating between JavaScript and Rust.
     Communication(String),
 }
+
+impl Display for EvalError {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        match self {
+            EvalError::Unsupported => write!(f, "EvalError::Unsupported - eval is not supported on the current platform"),
+            EvalError::Finished => write!(f, "EvalError::Finished - eval has already ran"),
+            EvalError::InvalidJs(_) => write!(f, "EvalError::InvalidJs - the provided javascript is invalid"),
+            EvalError::Communication(_) => write!(f, "EvalError::Communication - there was an error trying to communicate with between javascript and rust"),
+        }
+    }
+}
+
+impl Error for EvalError {}