From fe1248b73f409f50ca8109f3b464d7df37d3decd Mon Sep 17 00:00:00 2001 From: Matthew Ahrens Date: Thu, 27 Apr 2023 10:04:16 -0700 Subject: [PATCH] fix `zcachedb logs` entry printing (#826) When attempting to print chunks/entries (e.g. with `zcachedb logs --index`), if the `cffi::Slice` can be a direct memory (`Bytes`) reference, then the binary value of the entries is printed, rather than pretty-printing them. This commit provides a better `Debug` implementation for `cffi::Slice`, which fixes `zcachedb logs`. --- cmd/zfs_object_agent/util/src/cffi.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cmd/zfs_object_agent/util/src/cffi.rs b/cmd/zfs_object_agent/util/src/cffi.rs index 1c6c32903898..9868224dfc29 100644 --- a/cmd/zfs_object_agent/util/src/cffi.rs +++ b/cmd/zfs_object_agent/util/src/cffi.rs @@ -8,6 +8,9 @@ //! was written out, see block_encode.rs. use std::any::type_name; +use std::fmt; +use std::fmt::Debug; +use std::fmt::Formatter; use std::mem::align_of; use std::mem::size_of; use std::ops::Deref; @@ -116,12 +119,23 @@ pub fn bytes_to_slice(bytes: Bytes) -> Result> { } } -#[derive(Debug)] pub enum Slice { Referenced(Bytes), Owned(Vec), } +impl Debug for Slice { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + match self { + Slice::Referenced(_) => f + .debug_tuple("Slice::Referenced") + .field(&self.deref()) + .finish(), + Slice::Owned(_) => f.debug_tuple("Slice::Owned").field(&self.deref()).finish(), + } + } +} + impl Slice { pub fn new_owned(vec: Vec) -> Self { Slice::Owned(vec)