4 releases

0.2.1 Apr 26, 2024
0.2.0 Mar 27, 2024
0.1.1 Feb 13, 2024
0.1.0 Mar 11, 2023

#1486 in Filesystem

Download history 35/week @ 2024-03-12 73/week @ 2024-03-19 154/week @ 2024-03-26 132/week @ 2024-04-02 224/week @ 2024-04-09 54/week @ 2024-04-16 248/week @ 2024-04-23 139/week @ 2024-04-30 37/week @ 2024-05-07 46/week @ 2024-05-14 46/week @ 2024-05-21 26/week @ 2024-05-28 59/week @ 2024-06-04 28/week @ 2024-06-11 28/week @ 2024-06-18 43/week @ 2024-06-25

174 downloads per month
Used in cargo-files

MIT/Apache

18KB
350 lines

cargo-files

Latest version crates.io downloads Build Status Apache/MIT2.0 License

A tool to list all source files in a cargo crate.

Motivation

While I was writing cargo-derivefmt I found myself wishing for a simple way to get the source files in a cargo crate. I wasn't able to find an existing crate which did this, so I wrote this one.

This library is still a work-in-progress. There are likely many issues and unsupported situations.

CLI

For end users, we provide a CLI which lists all source files in a crate.

Installation

cargo install (crates.io)

cargo install cargo-files --locked

cargo install (master)

cargo install --git https://github.com/dcchut/cargo-files --locked

Usage

cargo files

Sample output

> cargo files
/home/dcchut/cargo-files/cargo-files/src/main.rs
/home/dcchut/cargo-files/cargo-files-core/src/lib.rs
/home/dcchut/cargo-files/cargo-files-core/src/parser.rs
/home/dcchut/cargo-files/cargo-files-core/tests/tests.rs
/home/dcchut/cargo-files/cargo-files-test/src/lib.rs

Developers

The cargo-files-core crate contains the logic underlying cargo-files, and can be reused by other applications that care about source files. At the moment the API is extremely simplistic, but any improvement suggestions are welcome!

Minimal example

use cargo_files_core::{get_targets, get_target_files, Error};

fn main() -> Result<(), Error> {
    // Each target (e.g. bin/lib) in your workspace will contribute a target.
    let targets = get_targets(None)?;
    for target in targets {
        // Get all the files related to a specific target.
        let files = get_target_files(&target)?;
        for file in files {
            println!("{}", file.display());
        }
    }
    
    Ok(())
}

Dependencies

~1–1.7MB
~36K SLoC