A fast, multi-threaded line counting utility written in Rust.

Related tags

Utilities xloc
Overview

xloc

A fast, multi-threaded line counting utility written in Rust.

What is xloc

  • A drop in replacement for bash's wc -l.

  • Your project has x lines of code, xloc gets the value of x for you.

  • xloc is itended to be used from the command line. You can use it to count the number of lines in a file, or aggregate the total number of lines of all files in a directory.

  • While command line utility was the focus, a public API has also been made available to use in your own rust projects in the form of xloc::App.

  • By default xloc will ignore any directory named target or .git. This will likely be configurable at a later date.

Getting started

xloc supports Rust version 1.24.0 and greater.

For more information, read the API Reference.


Installation

From the command line

cargo install xloc

As a package dependency

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

Usage

On the command line

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

# Count lines for 1 file, with 12 jobs.
xloc -j 12 test.txt

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

In a file

println!("{} lines", count), Err(e) => println!("Error: {}", e), } ">
// main.rs
use xloc::App;

fn main() {
    // Create a mutable `App` using 1 job.
    let mut app = App::new(1);
    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),
}

License

The xloc crate for Rust is licensed under the BSD 3-Clause License.

You might also like...
Pegasus: A Multi-Node Command Runner
Pegasus: A Multi-Node Command Runner

Run a list of commands on a set of SSH nodes. With a bit of optional parametrization.

An embedded-hal driver for the TT21100 multi-touch touchscreen controller

tt21100 An embedded-hal driver for the TT21100 multi-touch touchscreen controller. If there is a feature which has not yet been implemented and which

A rust-based version of the popular dnsgen python utility

ripgen A rust-based version of the popular dnsgen python utility. ripgen is split into two main parts: ripgen: A CLI utility that calls into ripgen_li

Tons of extension utility functions for Rust

LazyExt Tons of extension utility functions for Rust. English | 简体中文 Status Name Status Crate Documents Introduction lazyext-slice Alpha Thousands of

A simple string parsing utility library for Rust, supporting no_std contexts.

strp Utility library for parsing data from an input string, or stdin if built with the std feature. Supports no_std contexts when built without the st

A Rust utility library, making easier by taking the hassle out of working. :octocat:
A Rust utility library, making easier by taking the hassle out of working. :octocat:

reddish A Rust utility library, making easier by taking the hassle out of working. Usage Add this to your Cargo.toml: [dependencies] reddish = "0.2.0"

⏲ Situwaition is a Rust utility library that waits for conditions

⏲ situwaition situwaition runs a closure continuously, until an Ok(..) is received, or a timeout period elapses. Install cargo add situwaition

A command-line tool collection to assist development written in RUST

dtool dtool is a command-line tool collection to assist development Table of Contents Description Usage Tips Installation Description Now dtool suppor

Batch rename utility for developers
Batch rename utility for developers

nomino Batch rename utility for developers How to install Pre-Compiled You can download a pre-compiled executable for Linux, MacOS and Windows operati

Comments
  • Add test suite

    Add test suite

    Summary

    This PR adds a test suite to the lib.

    Additions

    • Full coverage of methods on App.
    • Full coverage of command line flags.
    • Some test data.
    • An improved regular expression for counting words.

    No API changes, or documentation changes.

    Closes #5

    testing 
    opened by Jonxslays 0
  • Add `-w` flag to count words instead of lines.

    Add `-w` flag to count words instead of lines.

    Summary

    This adds the -w flag for the command line to count words instead of lines. This flag is passed to App::new() as a boolean when using xloc from within a project.

    Breaking Changes

    • An additional parameter passed to the new() function for App.
    • Minimum supported rust version increased to 1.41.1.

    Additions

    • -w flag on the command line.
    • get_words and set_words methods implemented on App.

    All changes documented.

    Closes #1

    enhancement 
    opened by Jonxslays 0
  • Decrement thread count by 1

    Decrement thread count by 1

    • When a user passes no njobs to the command or app, and/or passes 1 job prevent any threads from spawning and just use the main thread.
    • When a user does specify more than 1 njobs, decrease that number by 1 to reserve that for the main thread.

    Closes #2

    opened by Jonxslays 0
Releases(v0.2.0)
  • v0.2.0(Nov 15, 2021)

    We can count words too, right?

    Summary

    v0.2.0 adds a new feature allowing you to count words. Thanks @IkBenOlie5 for the suggestion.

    Breaking changes

    • Minumum supported rust version increased to 1.41.1
    • Additional boolean parameter passed to App::new()

    Additions

    • Adds the ability to count words with the -w flag on the command line
    • Adds the ability to count words using App in a project
    • Testing suite

    Bug fixes

    • Fixes a bug where 1 extra thread would always be used when using multiple jobs
    • Various optimizations and redundancies removed
    Source code(tar.gz)
    Source code(zip)
  • v0.1.2(Nov 8, 2021)

  • v0.1.1(Nov 8, 2021)

  • v0.1.0(Nov 8, 2021)

Owner
Curious Python developer. Trying to re-write it in Rust. We can do this without a loop right?
null
mdTranslation is a utility to prepare multi-lingual Markdown documents.

mdTranslation is a utility to prepare multi-lingual Markdown documents. There's also a mdBook preprocessor called mdbook-translation for

Charles Lew 15 Dec 26, 2022
Rs.aws-login - A command line utility to simplify logging into AWS services.

aws-login A command line utility to simplify logging into AWS accounts and services. $ aws-login use ? Please select a profile to use: › ❯ dev-read

Kevin Herrera 11 Oct 30, 2022
ᎩᎦᎨᎢ (IPA: [gigagei]) is a random quote fetching console utility. Written in Rust.

gigagei ᎩᎦᎨᎢ (IPA: [gigagei]) is a random quote fetching console utility. Written in Rust. Installing Use latest pre-built binary from releases Buildi

veleth 10 Jun 17, 2022
A cli utility written in Rust that allows fetching all the labels of a project, save those as a YAML file

A cli utility written in Rust that allows fetching all the labels of a project, save those as a YAML file that you can easily edit or save as backup and apply a saved preset to new repositories.

Chevdor 4 May 5, 2022
Verbump - A simple utility written in rust to bump and manage git semantic version tags.

Verbump - A simple utility written in rust to bump and manage git semantic version tags.

Sarat Chandra 6 May 6, 2022
A working example of multi targets compilation for Rust using Github Actions.

A working example of multi targets compilation for Rust using Github Actions. Supports Windows, MacOSX, x86_64, ARM and Raspberry PI Linux.

Nicolas Vanhoren 41 Dec 17, 2022
Rust library to scan files and expand multi-file crates source code as a single tree

syn-file-expand This library allows you to load full source code of multi-file crates into a single syn::File. Features: Based on syn crate. Handling

Vitaly Shukela 11 Jul 27, 2022
Incremental, multi-version remote backup tool for block devices.

bsync Incremental, multi-version remote backup tool for block devices. The on-disk backup format is a SQLite database and I've been dogfooding this on

Heyang Zhou 7 Aug 21, 2022
Northstar is a horizontally scalable and multi-tenant Kubernetes cluster provisioner and orchestrator

Northstar Northstar is a horizontally scalable and multi-tenant Kubernetes cluster provisioner and orchestrator. Explore the docs » View Demo · Report

Lucas Clerisse 1 Jan 22, 2022
A timer based on a multi-time wheel structure

wheel-timer2 A timer based on a multi-time wheel structure This library uses a multi-layered time wheel structure. When a task is added to the wheel,

orange soeur 1 Jan 25, 2022