Add Kind
enum and method to get it's value from a u32
This commit is contained in:
parent
d69198d7f8
commit
2c8d05b9f8
31
src/lib.rs
31
src/lib.rs
@ -288,9 +288,7 @@ impl FileType {
|
|||||||
match self {
|
match self {
|
||||||
Self::Normal(f) => {
|
Self::Normal(f) => {
|
||||||
writer.write_all(&[0])?;
|
writer.write_all(&[0])?;
|
||||||
writer.write_all(&f.len.to_le_bytes())?;
|
f.write(writer)?;
|
||||||
f.checksum.write(writer)?;
|
|
||||||
writer.write_all(&f.data)?;
|
|
||||||
},
|
},
|
||||||
Self::HardLink(s) => {
|
Self::HardLink(s) => {
|
||||||
writer.write_all(&[1])?;
|
writer.write_all(&[1])?;
|
||||||
@ -319,6 +317,33 @@ impl FileType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum Kind {
|
||||||
|
Normal,
|
||||||
|
Dir,
|
||||||
|
Char,
|
||||||
|
Block,
|
||||||
|
Pipe,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<u32> for Kind {
|
||||||
|
fn from(value: u32) -> Self {
|
||||||
|
if value & 0o60000 != 0 {
|
||||||
|
Self::Block
|
||||||
|
} else if value & 0o20000 != 0 {
|
||||||
|
Self::Char
|
||||||
|
} else if value & 0o10000 != 0 {
|
||||||
|
Self::Pipe
|
||||||
|
} else if value & 0o40000 != 0 {
|
||||||
|
Self::Dir
|
||||||
|
} else if value & 0o100000 != 0 {
|
||||||
|
Self::Normal
|
||||||
|
} else {
|
||||||
|
panic!();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Node {
|
pub struct Node {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
Loading…
Reference in New Issue
Block a user