1#[cfg(feature = "alloc")]
9use alloc::{boxed::Box, string::String};
10
11use crate::{EdgeId, VertexId};
12
13pub type Result<T = ()> = core::result::Result<T, Error>;
15
16#[derive(Debug, thiserror::Error)]
18pub enum Error {
19 #[error("Index is out of bounds")]
20 IndexOutOfBounds,
21 #[error("Invalid index")]
22 InvalidIndex,
23 #[error("Cannot create empty hyperedge")]
24 EmptyHyperedge,
25 #[error("Hyperedge {0} does not exist")]
26 HyperedgeDoesNotExist(EdgeId<usize>),
27 #[error("Vertex {0} does not exist")]
28 VertexDoesNotExist(VertexId<usize>),
29 #[cfg(feature = "anyhow")]
30 #[error(transparent)]
31 AnyError(#[from] anyhow::Error),
32 #[cfg(feature = "serde_json")]
33 #[error(transparent)]
34 JsonError(#[from] serde_json::Error),
35 #[cfg(feature = "alloc")]
36 #[error(transparent)]
37 Other(#[from] Box<dyn core::error::Error + Send + Sync + 'static>),
38 #[cfg(feature = "alloc")]
39 #[error("Unknown error: {0}")]
40 Unknown(String),
41}
42
43#[cfg(feature = "alloc")]
44impl From<&str> for Error {
45 fn from(s: &str) -> Self {
46 Error::Unknown(String::from(s))
47 }
48}
49
50#[cfg(feature = "alloc")]
51impl From<String> for Error {
52 fn from(s: String) -> Self {
53 Error::Unknown(s)
54 }
55}