From 53570d13d7cc7b6301746356fd443c2dbb2d178f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Fri, 19 Jun 2020 18:46:21 +0100 Subject: [PATCH] Add Debug for dictionary --- src/util/dictionary/immutable.rs | 7 +++++++ src/util/dictionary/mutable.rs | 7 +++++++ src/util/dictionary/owned.rs | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/src/util/dictionary/immutable.rs b/src/util/dictionary/immutable.rs index 3781277..677faf1 100644 --- a/src/util/dictionary/immutable.rs +++ b/src/util/dictionary/immutable.rs @@ -1,4 +1,5 @@ use std::ffi::{CStr, CString}; +use std::fmt; use std::marker::PhantomData; use std::ptr; use std::str::from_utf8_unchecked; @@ -58,3 +59,9 @@ impl<'a> IntoIterator for &'a Ref<'a> { self.iter() } } + +impl<'a> fmt::Debug for Ref<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_map().entries(self.iter()).finish() + } +} diff --git a/src/util/dictionary/mutable.rs b/src/util/dictionary/mutable.rs index 5413dfd..241a39d 100644 --- a/src/util/dictionary/mutable.rs +++ b/src/util/dictionary/mutable.rs @@ -1,4 +1,5 @@ use std::ffi::CString; +use std::fmt; use std::marker::PhantomData; use std::ops::Deref; @@ -50,3 +51,9 @@ impl<'a> Deref for Ref<'a> { &self.imm } } + +impl<'a> fmt::Debug for Ref<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + self.imm.fmt(fmt) + } +} diff --git a/src/util/dictionary/owned.rs b/src/util/dictionary/owned.rs index 00d06ed..16f2ba0 100644 --- a/src/util/dictionary/owned.rs +++ b/src/util/dictionary/owned.rs @@ -1,3 +1,4 @@ +use std::fmt; use std::iter::FromIterator; use std::ops::{Deref, DerefMut}; use std::ptr; @@ -126,3 +127,9 @@ impl<'a> Drop for Owned<'a> { } } } + +impl<'a> fmt::Debug for Owned<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + self.inner.fmt(fmt) + } +}