Fix crash in DowncastError Display impl, remove String member
@@ -52,7 +52,6 @@ impl<'a, T: Managed + 'a> Handle<'a, T> {
pub struct DowncastError<F: Value, T: Value> {
phantom_from: PhantomData<F>,
phantom_to: PhantomData<T>,
- description: String
}
impl<F: Value, T: Value> Debug for DowncastError<F, T> {
@@ -66,22 +65,17 @@ impl<F: Value, T: Value> DowncastError<F, T> {
DowncastError {
phantom_from: PhantomData,
phantom_to: PhantomData,
- description: format!("failed downcast to {}", T::name())
}
}
}
impl<F: Value, T: Value> Display for DowncastError<F, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
- write!(f, "{}", self.to_string())
+ write!(f, "failed to downcast {} to {}", F::name(), T::name())
}
}
-impl<F: Value, T: Value> Error for DowncastError<F, T> {
- fn description(&self) -> &str {
- &self.description
- }
-}
+impl<F: Value, T: Value> Error for DowncastError<F, T> {}
/// The result of a call to `Handle::downcast()`.
pub type DowncastResult<'a, F, T> = Result<Handle<'a, T>, DowncastError<F, T>>;
@@ -90,7 +84,7 @@ impl<'a, F: Value, T: Value> JsResultExt<'a, T> for DowncastResult<'a, F, T> {
fn or_throw<'b, C: Context<'b>>(self, cx: &mut C) -> JsResult<'a, T> {
match self {
Ok(v) => Ok(v),
- Err(e) => cx.throw_type_error(&e.description)
+ Err(e) => cx.throw_type_error(&e.to_string())
}
}
}
