#fs-file #file #basic

filetype

This crate provides a basic extension to std::fs::File: it defines a method which returns the file’s type (on *nix systems)

2 unstable releases

Uses old Rust 2015

0.2.0 Apr 30, 2015
0.1.0 Apr 29, 2015

#48 in #fs-file

MIT license

8KB
112 lines

Build Status

API Documentation

This is a pet project, and not tested very well (contributions welcome!). Use at your own risk.

This crate provides a basic extension to std::fs::File: it defines a method which returns the file's type (on *nix systems).

extern crate filetype;

use std::fs;
use std::fs::File;
use filetype::{FileType, UnixFileType};

let f = File::open("foo").unwrap();
let ftype = f.file_type().unwrap();

match ftype {
    FileType::Regular => {},
    FileType::Directory => {},
    FileType::Symlink => {},
    FileType::NamedPipe => {},
    FileType::BlockDevice => {},
    FileType::CharacterDevice => {},
}

lib.rs:

This crate provides a basic extension to std::fs::File: it defines a method which returns the file's type (on *nix systems).

use std::fs;
use std::fs::File;
use filetype::{FileType, UnixFileType};

let f = File::open("foo").unwrap();
let ftype = f.file_type().unwrap();

match ftype {
    FileType::Regular => {},
    FileType::Directory => {
        # assert!(false);
    },
    FileType::Symlink => {
        # assert!(false);
    },
    FileType::NamedPipe => {
        # assert!(false);
    },
    FileType::BlockDevice => {
        # assert!(false);
    },
    FileType::CharacterDevice => {
        # assert!(false);
    },
}

Dependencies

~1.5MB
~35K SLoC