1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2016 Matthew Fornaciari <mattforni@gmail.com>
//! A dead simple wrapper around file and directory manipulation.
//!
//! # Usage
//!
//! This crate is [on crates.io](https://crates.io/crates/touch) and can be
//! used by adding `args` to the dependencies in your project's `Cargo.toml`.
//!
//! ```toml
//! [dependencies]
//! touch = "0"
//! ```
//!
//! and this to your crate root:
//!
//! ```rust
//! extern crate touch;
//! ```
//!
//! # Example
//!
//! ```rust
//! 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)
//! }
//! ```
extern crate log;
use Path;
use result;
/// A specialized Result type for I/O operations.
///
/// This type is broadly used across the `touch` crate for any operation which
/// may produce an error.
pub type Result<T> = Result;
pub use Error;
/// Returns whether or not the file at the provided path exists.