Jonas Platte 6609829735 Add 'crates/ruma-state-res/' from commit '56bf45c0235701ac6df56993c327d2f97a499ef9'
git-subtree-dir: crates/ruma-state-res
git-subtree-mainline: 719433eb5c41fb5b8099481ce7bb0a37931b260f
git-subtree-split: 56bf45c0235701ac6df56993c327d2f97a499ef9
2021-05-08 00:20:05 +02:00

36 lines
882 B
Rust

use serde_json::Error as JsonError;
use thiserror::Error;
/// Result type for state resolution.
pub type Result<T> = std::result::Result<T, Error>;
/// Represents the various errors that arise when resolving state.
#[derive(Error, Debug)]
pub enum Error {
/// A deserialization error.
#[error(transparent)]
SerdeJson(#[from] JsonError),
/// The given option or version is unsupported.
#[error("Unsupported room version: {0}")]
Unsupported(String),
/// The given event was not found.
#[error("Not found error: {0}")]
NotFound(String),
/// Invalid fields in the given PDU.
#[error("Invalid PDU: {0}")]
InvalidPdu(String),
/// A custom error.
#[error("{0}")]
Custom(Box<dyn std::error::Error>),
}
impl Error {
pub fn custom<E: std::error::Error + 'static>(e: E) -> Self {
Self::Custom(Box::new(e))
}
}