#directory #file #fs

touch

A thin wrapper around file and directory operations designed to take remove some of tediousness

1 unstable release

Uses old Rust 2015

0.0.1 Jun 22, 2016

#136 in #fs

Download history 32/week @ 2024-03-11 34/week @ 2024-03-18 50/week @ 2024-03-25 64/week @ 2024-04-01 28/week @ 2024-04-08 23/week @ 2024-04-15 31/week @ 2024-04-22 23/week @ 2024-04-29 27/week @ 2024-05-06 39/week @ 2024-05-13 26/week @ 2024-05-20 27/week @ 2024-05-27 66/week @ 2024-06-03 24/week @ 2024-06-10 24/week @ 2024-06-17 43/week @ 2024-06-24

158 downloads per month
Used in 11 crates (5 directly)

MIT license

18KB
366 lines

touch

Copyright 2016 Matthew Fornaciari mattforni@gmail.com A dead simple wrapper around file and directory manipulation.

Usage

This crate is on crates.io and can be used by adding args to the dependencies in your project's Cargo.toml.

[dependencies]
touch = "0"

and this to your crate root:

extern crate touch;

Example

extern crate touch;

use touch::exists;
use touch::dir;
use touch::file;

const DIR: &'static str = "/tmp/touch";
const FILE_NAME: &'static str = ".example";

fn main() {
    assert!(!exists(DIR));
    assert!(!exists(&path()));

    // Write
    let content = "Content";
    assert!(file::write(&path(), content, false).is_ok());

    // Read
    let mut output = file::read(&path());
    assert_eq!(content, output.unwrap());

    // Overwrite
    let new_content = "New Content";
    assert!(file::write(&path(), new_content, true).is_ok());
    output = file::read(&path());
    assert_eq!(new_content, output.unwrap());

    // Delete
    assert!(dir::delete(DIR).is_ok());
    assert!(!exists(&path()));
    assert!(!exists(DIR));
}

fn path() -> String {
    format!("{}/{}", DIR, FILE_NAME)
}

Dependencies

~87KB