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) shell cargo install cargo-files --locked

cargo install (master) shell cargo install --git https://github.com/dcchut/cargo-files --locked

Usage

shell 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

```rust use cargofilescore::{gettargets, gettarget_files, Error};

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

Ok(())

} ```