Impl From<Node> for Listing
This commit is contained in:
parent
63b414b7fd
commit
b25a49260e
@ -5,7 +5,7 @@ use {
|
|||||||
};
|
};
|
||||||
|
|
||||||
use {
|
use {
|
||||||
crate::{filetype::Flag, Error, Special},
|
crate::{filetype::Flag, Error, FileType, Node, Special},
|
||||||
chrono::NaiveDateTime,
|
chrono::NaiveDateTime,
|
||||||
std::{
|
std::{
|
||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
@ -26,6 +26,21 @@ pub enum Kind {
|
|||||||
Eof,
|
Eof,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<FileType> 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 {
|
impl Kind {
|
||||||
#[allow(clippy::cast_possible_wrap)]
|
#[allow(clippy::cast_possible_wrap)]
|
||||||
fn read<R: Read + Seek>(reader: &mut R, flag: Flag) -> Result<Self, Error> {
|
fn read<R: Read + Seek>(reader: &mut R, flag: Flag) -> Result<Self, Error> {
|
||||||
@ -97,6 +112,19 @@ pub struct Listing {
|
|||||||
pub kind: Kind,
|
pub kind: Kind,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Node> 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 {
|
impl PartialOrd for Listing {
|
||||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||||
Some(self.cmp(other))
|
Some(self.cmp(other))
|
||||||
|
Loading…
Reference in New Issue
Block a user