1use std::borrow::Cow;
2
3use meowtonin::ByondError;
4use serde::{de, ser};
5
6#[derive(Debug, thiserror::Error)]
7pub enum SerializeError {
8 #[error("byondapi error: {0}")]
9 Byond(#[from] ByondError),
10 #[error("expected {0}")]
11 Expected(&'static str),
12 #[error("{0}")]
13 Custom(String),
14}
15
16impl ser::Error for SerializeError {
17 fn custom<T>(msg: T) -> Self
18 where
19 T: std::fmt::Display,
20 {
21 Self::Custom(msg.to_string())
22 }
23}
24
25#[derive(Debug, thiserror::Error)]
26pub enum DeserializeError {
27 #[error("byondapi error: {0}")]
28 Byond(#[from] ByondError),
29 #[error("expected {0}, got {1}")]
30 Unexpected(Cow<'static, str>, Cow<'static, str>),
31 #[error("attempted to fetch element from end of array")]
32 EndOfArray,
33 #[error("{0}")]
34 Custom(String),
35}
36
37impl de::Error for DeserializeError {
38 fn custom<T>(msg: T) -> Self
39 where
40 T: std::fmt::Display,
41 {
42 Self::Custom(msg.to_string())
43 }
44}