From 64346ce56cd29add150fe96872ee1dc56d532f99 Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Mon, 3 May 2021 13:05:43 +0100 Subject: [PATCH] Implement/Derive `Debug` for Lua and few other structs --- src/lua.rs | 10 +++++++++- src/serde/de.rs | 1 + src/serde/ser.rs | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/lua.rs b/src/lua.rs index e216433..e441f24 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -2,6 +2,7 @@ use std::any::TypeId; use std::cell::{RefCell, UnsafeCell}; use std::collections::{HashMap, HashSet}; use std::ffi::CString; +use std::fmt; use std::marker::PhantomData; use std::os::raw::{c_char, c_int, c_void}; use std::panic::resume_unwind; @@ -88,6 +89,7 @@ struct MemoryInfo { /// More information can be found in the Lua 5.x [documentation]. /// /// [documentation]: https://www.lua.org/manual/5.4/manual.html#2.5 +#[derive(Clone, Copy, Debug)] pub enum GCMode { Incremental, /// Requires `feature = "lua54"` @@ -128,6 +130,12 @@ impl Drop for Lua { } } +impl fmt::Debug for Lua { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Lua({:p})", self.state) + } +} + impl Lua { /// Creates a new Lua state and loads the **safe** subset of the standard libraries. /// @@ -1942,7 +1950,7 @@ pub struct Chunk<'lua, 'a> { } /// Represents chunk mode (text or binary). -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] pub enum ChunkMode { Text, Binary, diff --git a/src/serde/de.rs b/src/serde/de.rs index fe7ca38..c6ae8b7 100644 --- a/src/serde/de.rs +++ b/src/serde/de.rs @@ -7,6 +7,7 @@ use crate::table::{TablePairs, TableSequence}; use crate::value::Value; /// A struct for deserializing Lua values into Rust values. +#[derive(Debug)] pub struct Deserializer<'lua>(Value<'lua>); impl<'lua> Deserializer<'lua> { diff --git a/src/serde/ser.rs b/src/serde/ser.rs index 820f42f..f8b0b17 100644 --- a/src/serde/ser.rs +++ b/src/serde/ser.rs @@ -13,6 +13,7 @@ use crate::util::{check_stack, StackGuard}; use crate::value::{ToLua, Value}; /// A struct for serializing Rust values into Lua values. +#[derive(Debug)] pub struct Serializer<'lua> { lua: &'lua Lua, options: Options,