medea_jason/utils/
errors.rs

1//! Helpers for application errors.
2
3use std::rc::Rc;
4
5use derive_more::with_trait::{Display, From};
6pub use medea_macro::Caused;
7
8/// Representation of an error caused by FFI side.
9pub trait Caused {
10    /// Type of a wrapper for the FFI error.
11    type Error;
12
13    /// Returns the FFI error if represents the cause.
14    fn cause(self) -> Option<Self::Error>;
15}
16
17/// Wrapper for [`serde_json::Error`] that provides [`Clone`], [`Debug`],
18/// [`Display`] implementations.
19///
20/// [`Debug`]: std::fmt::Debug
21/// [`Display`]: std::fmt::Display
22#[derive(Clone, Debug, Display, From)]
23#[from(forward)]
24pub struct JsonParseError(Rc<serde_json::Error>);
25
26impl PartialEq for JsonParseError {
27    fn eq(&self, other: &Self) -> bool {
28        self.0.line() == other.0.line()
29            && self.0.column() == other.0.column()
30            && self.0.classify() == other.0.classify()
31    }
32}