#line-count #line #count #code

bin+lib xloc

使用 Rust 编写的快速多线程行数统计工具

4 个版本

0.2.0 2021 年 11 月 15 日
0.1.2 2021 年 11 月 8 日
0.1.1 2021 年 11 月 8 日
0.1.0 2021 年 11 月 7 日

#482 in 并发

BSD-3-Clause

19KB
359 代码行

xloc

使用 Rust 编写的快速多线程行数统计工具。

什么是 xloc

  • 类似于 bash 的 wc 命令,但可以并发运行。

  • 您的项目有 x 行代码,xloc 会为您获取 x 的值。

  • xloc 旨在通过命令行使用。您可以使用它来统计文件中的行数/单词数,或统计目录中所有文件的行数/单词数的总和。

  • 尽管命令行工具是重点,但还提供了一个公共 API,以 xloc::App 的形式供您在 Rust 项目中使用。

  • 默认情况下,xloc 将忽略名为 target.git 的任何目录。这可能在以后可配置。

入门指南

xloc 支持 Rust 版本 1.41.1 及以上。

有关更多信息,请阅读 API 参考


安装

从命令行

cargo install xloc

作为包依赖项

# Cargo.toml
[dependencies]
xloc = "^0.2"

用法

在命令行上

# Count lines for all files in the current dir, with 1 job.
xloc .

# Count words for all files in the current dir with nproc jobs.
xloc -wj $(nproc) .

# Count words for 1 file, with 1 job.
xloc -w test.txt

# Count lines for all files in the src dir, with 6 jobs.
xloc -j 6 src

在文件中

// main.rs
use xloc::App;

fn main() {
    // Create a mutable `App` using 1 job.
    let mut app = App::default();
    assert_eq!(app.get_njobs(), 1);

    // Set the number of jobs to 12.
    app.set_njobs(12);
    assert_eq!(app.get_njobs(), 12);

    // Recursively count lines in the current dir.
    match app.count(".") {
        Ok(count) => println!("{} lines", count),
        Err(e) => println!("Error: {}", e),
    }
}

许可证

Rust 的 xloc 包根据 BSD 3-Clause 许可证 许可。

依赖关系

~2.7–4MB
~59K SLoC