mirror of
https://github.com/Zenithsiz/dcb.git
synced 2026-02-05 16:53:47 +00:00
Removed some bounds on DirWriterLister by hand-implementing derives.
This commit is contained in:
parent
5504ace431
commit
529263d5d3
@ -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<L: DirWriterLister> {
|
||||
/// A file
|
||||
File(FileWriter<L::FileReader>),
|
||||
@ -17,8 +16,19 @@ pub enum DirEntryWriterKind<L: DirWriterLister> {
|
||||
Dir(DirWriter<L>),
|
||||
}
|
||||
|
||||
impl<L: DirWriterLister + fmt::Debug> fmt::Debug for DirEntryWriterKind<L>
|
||||
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<L: DirWriterLister> {
|
||||
/// Entry name
|
||||
name: AsciiStrArr<0x10>,
|
||||
@ -30,6 +40,19 @@ pub struct DirEntryWriter<L: DirWriterLister> {
|
||||
kind: DirEntryWriterKind<L>,
|
||||
}
|
||||
|
||||
impl<L: DirWriterLister + fmt::Debug> fmt::Debug for DirEntryWriter<L>
|
||||
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<L: DirWriterLister> DirEntryWriter<L> {
|
||||
/// Creates a new entry writer from it's name, date and kind
|
||||
pub fn new(name: AsciiStrArr<0x10>, date: NaiveDateTime, kind: DirEntryWriterKind<L>) -> Self {
|
||||
|
||||
@ -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<Item = Result<DirEntryWriter<Self>, <Self as DirWriterLister>::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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user