#read-write #directory #os #bundle #awesome #time

etc

It's time to bundle etc for your awesome project!

21 releases

0.1.19 Jan 22, 2024
0.1.18 Dec 29, 2023
0.1.16 Dec 9, 2020
0.1.12 Oct 29, 2020
0.1.2 Mar 22, 2020

#106 in Filesystem

Download history 777/week @ 2023-12-20 683/week @ 2023-12-27 695/week @ 2024-01-03 985/week @ 2024-01-10 860/week @ 2024-01-17 413/week @ 2024-01-24 499/week @ 2024-01-31 495/week @ 2024-02-07 315/week @ 2024-02-14 514/week @ 2024-02-21 542/week @ 2024-02-28 454/week @ 2024-03-06 456/week @ 2024-03-13 679/week @ 2024-03-20 506/week @ 2024-03-27 517/week @ 2024-04-03

2,265 downloads per month
Used in 15 crates (13 directly)

MIT license

21KB
431 lines

etc

crate doc downloads LICENSE

It's time to bundle etc for your awesome project!

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};

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());
}

Projects using etc

  • elvis - Webassembly UI framework
  • sup - Substrate package manager

LICENSE

MIT

Dependencies

~180KB