This is unreleased documentation for the main (development) branch of serde_luaq.
You can find the latest stable documentation on docs.rs.

serde_luaq/
error.rs

1use serde::{de, ser};
2use std::fmt::Display;
3#[cfg(feature = "serde_json")]
4use std::str::Utf8Error;
5use thiserror::Error as ThisError;
6
7pub type Result<T> = std::result::Result<T, Error>;
8
9#[derive(Debug, ThisError, PartialEq, Eq)]
10pub enum Error {
11    #[error("serde deserialize error: {0}")]
12    SerdeDeserialize(String),
13    #[error("serde serialize error: {0}")]
14    SerdeSerialize(String),
15    #[error("peg parse error: {0:?}")]
16    Peg(#[from] peg::error::ParseError<usize>),
17}
18
19impl ser::Error for Error {
20    fn custom<T: Display>(msg: T) -> Self {
21        Error::SerdeSerialize(msg.to_string())
22    }
23}
24
25impl de::Error for Error {
26    fn custom<T: Display>(msg: T) -> Self {
27        Error::SerdeDeserialize(msg.to_string())
28    }
29}
30
31#[cfg(feature = "serde_json")]
32/// Errors when converting Lua to JSON.
33#[derive(Debug, ThisError, PartialEq)]
34pub enum JsonConversionError {
35    #[error("positive infinity cannot be represented in standard JSON")]
36    PositiveInfinity,
37
38    #[error("negative infinity cannot be represented in standard JSON")]
39    NegativeInfinity,
40
41    #[error("NaN cannot be represented in standard JSON")]
42    NaN,
43
44    #[error("unknown floating point conversion failure")]
45    Float,
46
47    #[error("UTF-8 encoding error: {0:?}")]
48    Utf8Error(#[from] Utf8Error),
49
50    #[error("Lua table contains a table as a key")]
51    TableKeyedWithTable,
52}
53
54#[cfg(feature = "serde_json")]
55/// Errors when converting JSON to Lua.
56#[derive(Debug, ThisError, PartialEq)]
57pub enum LuaConversionError {
58    #[error("Lua numbers must fit in `i64` or `f64`")]
59    Number,
60}