aboutsummaryrefslogtreecommitdiff
path: root/src/lua/serde/error.rs
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2022-08-13 03:56:55 +0200
committerMartin Fischer <martin@push-f.com>2022-08-14 00:33:23 +0200
commit36e98c1b135f07ef9a5eec046b8f0fd6d93534d4 (patch)
treeda9c93ceb0e147695e1992c4d1678964af3be4bf /src/lua/serde/error.rs
parentdc20e1df60c1e4e81d1e16e8f177a1c6956966b7 (diff)
add gitpad.decode_toml lua method
We are vendoring the rlua_serde crate because it currently depends on rlua 0.17, which is outdated and my attempts to contact the crate author were bounced by Yandex for somehow looking like spam.
Diffstat (limited to 'src/lua/serde/error.rs')
-rw-r--r--src/lua/serde/error.rs58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/lua/serde/error.rs b/src/lua/serde/error.rs
new file mode 100644
index 0000000..8d5debf
--- /dev/null
+++ b/src/lua/serde/error.rs
@@ -0,0 +1,58 @@
+// vendored from https://github.com/zrkn/rlua_serde because it dependend on an outdated rlua version
+// Copyright (c) 2018 zrkn <zrkn@email.su>, licensed under the MIT License
+
+use std::error::Error as StdError;
+use std::fmt;
+use std::result::Result as StdResult;
+
+use rlua::Error as LuaError;
+use serde;
+
+#[derive(Debug)]
+pub struct Error(LuaError);
+
+pub type Result<T> = StdResult<T, Error>;
+
+impl From<LuaError> for Error {
+ fn from(err: LuaError) -> Error {
+ Error(err)
+ }
+}
+
+impl From<Error> for LuaError {
+ fn from(err: Error) -> LuaError {
+ err.0
+ }
+}
+
+impl fmt::Display for Error {
+ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+ self.0.fmt(fmt)
+ }
+}
+
+impl StdError for Error {
+ fn description(&self) -> &'static str {
+ "Failed to serialize to Lua value"
+ }
+}
+
+impl serde::ser::Error for Error {
+ fn custom<T: fmt::Display>(msg: T) -> Self {
+ Error(LuaError::ToLuaConversionError {
+ from: "serialize",
+ to: "value",
+ message: Some(format!("{}", msg)),
+ })
+ }
+}
+
+impl serde::de::Error for Error {
+ fn custom<T: fmt::Display>(msg: T) -> Self {
+ Error(LuaError::FromLuaConversionError {
+ from: "value",
+ to: "deserialize",
+ message: Some(format!("{}", msg)),
+ })
+ }
+}