From b25a49260e77897e1db2a2f491fd578217ad1296 Mon Sep 17 00:00:00 2001 From: Nathan Fisher Date: Mon, 1 Jan 2024 18:30:24 -0500 Subject: [PATCH] Impl From for Listing --- src/listing.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/listing.rs b/src/listing.rs index 8ff2b93..f5457b1 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -5,7 +5,7 @@ use { }; use { - crate::{filetype::Flag, Error, Special}, + crate::{filetype::Flag, Error, FileType, Node, Special}, chrono::NaiveDateTime, std::{ cmp::Ordering, @@ -26,6 +26,21 @@ pub enum Kind { Eof, } +impl From for Kind { + fn from(value: FileType) -> Self { + match value { + FileType::Normal(f) => Self::Normal(f.len), + FileType::HardLink(tgt) => Self::HardLink(tgt), + FileType::SoftLink(tgt) => Self::SoftLink(tgt), + FileType::Directory => Self::Directory, + FileType::Character(c) => Self::Character(c), + FileType::Block(b) => Self::Block(b), + FileType::Fifo => Self::Fifo, + FileType::Eof => Self::Eof, + } + } +} + impl Kind { #[allow(clippy::cast_possible_wrap)] fn read(reader: &mut R, flag: Flag) -> Result { @@ -97,6 +112,19 @@ pub struct Listing { pub kind: Kind, } +impl From for Listing { + fn from(value: Node) -> Self { + Self { + name: value.name, + uid: value.uid, + gid: value.gid, + mtime: value.mtime, + mode: value.mode, + kind: value.filetype.into(), + } + } +} + impl PartialOrd for Listing { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other))