5 releases

0.1.4 Apr 15, 2024
0.1.3 Oct 4, 2023
0.1.2 Sep 27, 2023
0.1.1 Sep 27, 2023
0.1.0 Sep 27, 2023

#490 in Filesystem

Download history 2/week @ 2024-02-14 7/week @ 2024-02-21 2/week @ 2024-02-28 2/week @ 2024-03-06 5/week @ 2024-03-13 14/week @ 2024-03-27 15/week @ 2024-04-03 125/week @ 2024-04-10 27/week @ 2024-04-17 3/week @ 2024-04-24

63 downloads per month

MIT/Apache

37KB
780 lines

dir-structure

A library to make it easier to represent directory structures as plain Rust structures, and reducing the boiler-plate associated with creating and manipulating them.

A quick example:

#[derive(dir_structure::DirStructure)]
struct Dir {
    #[dir_structure(path = "input.txt")]
    input: String,
    #[dir_structure(path = "output.txt")]
    output: String,
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    use dir_structure::DirStructureItem;
    let path = std::path::Path::new("my_dir");
    // to read a `Dir` instance
    let dir = Dir::read(path)?;
    // to write a `Dir` instance
    dir.write(path)?;
    
    // or simply with a struct literal
    Dir {
        input: "Hello, world!".to_string(),
        output: "Hello, world!".to_string(),
    }.write(path)?;
    
    Ok(())
}

This blog post goes a bit more in-depth about the more advanced features of the library.

Dependencies

~0.3–1MB
~22K SLoC