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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
//! # etc
//!
//! [](https://github.com/clearloop/etc)
//! [](https://crates.io/crates/etc)
//! [](https://docs.rs/etc/)
//! [](https://deps.rs/repo/github/clearloop/etc)
//! [](https://crates.io/crates/etc)
//! [](https://choosealicense.com/licenses/mit/)
//!
//! It's time to bundle etc for your awesome project!
//!
//! ```rust
//! use etc::{Etc, FileSystem, Read, Write};
//!
//! fn main() {
//! // config root path
//! let mut dir = std::env::temp_dir();
//! dir.push(".etc.io");
//!
//! // generate `/.etc.io` dir
//! let etc = Etc::new(&dir).unwrap();
//! let hello = etc.open("hello.md").unwrap();
//!
//! // input and output
//! assert!(hello.write(b"hello, world!\n").is_ok());
//! assert_eq!(hello.read().unwrap(), b"hello, world!\n");
//!
//! // remove hello.md
//! assert!(etc.rm("hello.md").is_ok());
//!
//! // hello.md has been removed
//! let mut hello_md = dir.clone();
//! hello_md.push("hello.md");
//! assert!(!hello_md.exists());
//!
//! // remove all
//! assert!(etc.drain().is_ok());
//! assert!(!dir.exists());
//! }
//! ```
//!
//! ## Loading dir with files' content into one struct!
//!
//! ```
//! use etc::{Etc, Tree, FileSystem, Write};
//! use std::{
//! env,
//! iter::FromIterator,
//! path::PathBuf,
//! };
//!
//! fn main() {
//! // config root path
//! let mut dir = env::temp_dir();
//! dir.push(".etc.load");
//!
//! // write files
//! let etc = Etc::new(&dir).unwrap();
//! let amd = etc.open("mds/a.md").unwrap();
//! let bmd = etc.open("mds/b.md").unwrap();
//! assert!(amd.write(b"# hello").is_ok());
//! assert!(bmd.write(b"# world").is_ok());
//!
//! // batch and load
//! let mut tree = Tree::batch(&etc).unwrap();
//! assert!(tree.load().is_ok());
//! assert_eq!(
//! tree,
//! Tree {
//! path: PathBuf::from(&dir),
//! content: None,
//! children: Some(vec![Tree {
//! path: PathBuf::from_iter(&[&dir, &PathBuf::from("mds")]),
//! content: None,
//! children: Some(vec![
//! Tree {
//! path: PathBuf::from_iter(&[&dir, &PathBuf::from("mds/a.md")]),
//! content: Some(b"# hello".to_vec()),
//! children: None,
//! },
//! Tree {
//! path: PathBuf::from_iter(&[&dir, &PathBuf::from("mds/b.md")]),
//! content: Some(b"# world".to_vec()),
//! children: None,
//! }
//! ])
//! }]),
//! }
//! );
//!
//! // remove all
//! assert!(etc.drain().is_ok());
//! assert!(!dir.exists());
//! }
//! ```
//! ## LICENSE
//!
//! MIT
#![allow(clippy::needless_doctest_main)]
#![warn(missing_docs)]
mod cmd;
mod error;
mod etc;
mod fs;
mod io;
mod meta;
mod tree;
pub use crate::{
cmd::*,
error::Error,
etc::Etc,
fs::FileSystem,
io::{Read, Write},
meta::Meta,
tree::Tree,
};