From 529263d5d3785221cef042d06c0143e0984a714b Mon Sep 17 00:00:00 2001 From: Filipe Rodrigues Date: Wed, 27 Jan 2021 09:25:55 +0000 Subject: [PATCH] Removed some bounds on `DirWriterLister` by hand-implementing derives. --- dcb-io/src/drv/dir/entry/writer.rs | 29 ++++++++++++++++++++++++++--- dcb-io/src/drv/dir/writer/lister.rs | 4 ++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/dcb-io/src/drv/dir/entry/writer.rs b/dcb-io/src/drv/dir/entry/writer.rs index 3f149f7..3723405 100644 --- a/dcb-io/src/drv/dir/entry/writer.rs +++ b/dcb-io/src/drv/dir/entry/writer.rs @@ -5,10 +5,9 @@ use crate::drv::{DirWriter, DirWriterLister, FileWriter}; use byteorder::{ByteOrder, LittleEndian}; use chrono::NaiveDateTime; use dcb_util::{array_split_mut, AsciiStrArr}; -use std::convert::TryFrom; +use std::{convert::TryFrom, fmt}; /// A directory entry writer kind -#[derive(Debug)] pub enum DirEntryWriterKind { /// A file File(FileWriter), @@ -17,8 +16,19 @@ pub enum DirEntryWriterKind { Dir(DirWriter), } +impl fmt::Debug for DirEntryWriterKind +where + L::FileReader: std::fmt::Debug, +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::File(file) => f.debug_tuple("File").field(file).finish(), + Self::Dir(dir) => f.debug_tuple("Dir").field(dir).finish(), + } + } +} + /// A directory entry writer -#[derive(Debug)] pub struct DirEntryWriter { /// Entry name name: AsciiStrArr<0x10>, @@ -30,6 +40,19 @@ pub struct DirEntryWriter { kind: DirEntryWriterKind, } +impl fmt::Debug for DirEntryWriter +where + L::FileReader: std::fmt::Debug, +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("DirEntryWriter") + .field("name", &self.name) + .field("date", &self.date) + .field("kind", &self.kind) + .finish() + } +} + impl DirEntryWriter { /// Creates a new entry writer from it's name, date and kind pub fn new(name: AsciiStrArr<0x10>, date: NaiveDateTime, kind: DirEntryWriterKind) -> Self { diff --git a/dcb-io/src/drv/dir/writer/lister.rs b/dcb-io/src/drv/dir/writer/lister.rs index ba89601..13c4267 100644 --- a/dcb-io/src/drv/dir/writer/lister.rs +++ b/dcb-io/src/drv/dir/writer/lister.rs @@ -24,12 +24,12 @@ use std::io; /// directory tree as much. /// This is, of course, provided the implementor supplies directories /// before the files, else they will not be placed at the start. -pub trait DirWriterLister: Sized + std::fmt::Debug +pub trait DirWriterLister: Sized where Self: IntoIterator, ::Error>>, { /// Type used to read all files in this directory tree - type FileReader: std::fmt::Debug + io::Read; + type FileReader: io::Read; /// Error type for each entry type Error: std::error::Error + 'static;