⚡️Highly efficient data and string formatting library for Rust.

Overview


License: MIT Crates.io (latest) codecov CI CD Tests

⚡️Highly efficient data and string formatting library for Rust.

🔎 Overview

Pad and format string slices and generic vectors efficiently with minimal memory allocation. This crate has guaranteed performance improvements over the standard library format! macro. Clone this repo and run cargo bench to see benchmark comparisons between our implementation and the standard library.

The library defines a core trait called Source and also has this implemented on two main types of datastructures, the string slice &str and a generic vector Vec<T> with some trait bounds on the type T. This allows for any developer to implement the trait on any datastructure that they want to be able to pad or format using any of the padding modes defined in the crate.

📦 Installation

The easiest way to include padder in your projects is by using the Cargo package manager.

$ cargo add padder

Alternatively, you can build from source by cloning this repo and compiling using Cargo and then linking the library to your project.

$ git clone https://github.com/firelink-data/padder.git
$ cd padder
$ cargo build --release

🚀 Examples

Adding padder to your crate dependecy will bring the Source trait into scope and allow padding.

You can for example pad string slices very easily in the following way:

let padded: String = "cool".pad(10, Alignment::Center, Symbol::Zero);

which would produce the padded String 000cool000. You can also pad to an already allocated buffer, allowing you full control of heap allocations, like below:

let width: usize = 8;
let mut output: Vec<u8> = Vec::with_capacity(width);
let original = vec![13u8, 9, 128, 81];
original.pad_and_push_to_buffer(width, Alignment::Right, Symbol::Whitespace, output);

There also exists two wrapper methods simply called pad and pad_and_push_to_buffer which allows padding any object as long as it implements the Source trait. You can for example use these functions like below:

// pad
let original: &str = "hej";
let width: usize = 9;
let output: String = pad(original, width, Alignment::Left, Symbol::Hyphen);

// pad_and_push_to_buffer
let buffer = String::with_capacity(11);
pad_and_push_to_buffer("testcool", 11, Alignment::Right, Symbol::Whitespace);

which would produce the strings hej------ and testcool.

📋 License

All code is to be held under a general MIT license, please see LICENSE for specific information.

You might also like...
Schemars is a high-performance Python serialization library, leveraging Rust and PyO3 for efficient handling of complex objects

Schemars Introduction Schemars is a Python package, written in Rust and leveraging PyO3, designed for efficient and flexible serialization of Python c

Pure-Rust implementation of Fast Static Symbol Tables string compression

fsst-rs A pure-Rust, zero-dependency implementation of the FSST string compression algorithm. FSST is a string compression algorithm meant for use in

UnixString is An FFI-friendly null-terminated byte string

UnixString is an FFI-friendly null-terminated byte string that may be constructed from a String, a CString, a PathBuf, an OsString or a collection of bytes.

Write a simple CLI script, that when given a 64-byte encoded string

Write a simple CLI script, that when given a 64-byte encoded string, it finds a suitable 4-byte prefix so that, a SHA256 hash of the prefix combined with the original string of bytes, has two last bytes as 0xca, 0xfe. Script should expect the original content of the string to be passed in hexadecimal format and should return two lines, first being the SHA256 string found and second 4-byte prefix used (in hexadecimal format).

Chemical structure generation for protein sequences as SMILES string.
Chemical structure generation for protein sequences as SMILES string.

proteinogenic Chemical structure generation for protein sequences as SMILES string. 🔌 Usage This crate builds on top of purr, a crate providing primi

`matchable` provides a convenient enum for checking if a piece of text is matching a string or a regex.

matchable matchable provides a convenient enum for checking if a piece of text is matching a string or a regex. The common usage of this crate is used

Concurrent and multi-stage data ingestion and data processing with Rust+Tokio

TokioSky Build concurrent and multi-stage data ingestion and data processing pipelines with Rust+Tokio. TokioSky allows developers to consume data eff

Command line tool for cheap and efficient email automation written in Rust

Pigeon Pigeon is a command line tool for automating your email workflow in a cheap and efficient way. Utilize your most efficient dev tools you are al

An open source, programmed in rust, privacy focused tool for reading programming resources (like stackoverflow) fast, efficient and asynchronous from the terminal.

Falion An open source, programmed in rust, privacy focused tool for reading programming resources (like StackOverFlow) fast, efficient and asynchronou

Releases(v1.0.0)
  • v1.0.0(Dec 19, 2023)

    First major release 🔥⚡️

    This is the first major release of padder. At face value, it offers any Rust developer an alternative to using the standard library macro format! which has known performance issues due to multiple allocations.

    Padder allocates memory once, and then uses that memory for your formatting and padding needs. Check out the docs for examples and more information. The padding trait is currently implemented for string slices &str and generic vectors Vec<T>, with some trait bounds necessary.

    Sadly no new contributors for this major release. However, feel free to contribute in any way if you see something that can be added or improved.

    📋 Changelog:

    • [build] bump to major release v0.1.1 → v1.0.0 (https://github.com/firelink-data/padder/pull/13)
    • [docs] udpate description in readme (https://github.com/firelink-data/padder/pull/11)
    • [feat] trait bounds for char and u8 on Source trait (https://github.com/firelink-data/padder/pull/10)
    • [docs] update readme short description (https://github.com/firelink-data/padder/pull/9)
    • [crate] bump package version to 0.1.1 (https://github.com/firelink-data/padder/pull/8)
    • [docs] fix typo in readme (https://github.com/firelink-data/padder/pull/7)
    • [feat] document and improve padding functionality (https://github.com/firelink-data/padder/pull/6)
    • [build] update package description (https://github.com/firelink-data/padder/pull/5)
    • [docs] add install instructions and badges (https://github.com/firelink-data/padder/pull/4)
    • [feat] padding, testing, and benchmarking (https://github.com/firelink-data/padder/pull/3)
    • [git] dependabot config, ci and tests workflows (https://github.com/firelink-data/padder/pull/2)
    • [build] add ci and tests workflows (https://github.com/firelink-data/padder/pull/1)
    Source code(tar.gz)
    Source code(zip)
Owner
Firelink Data
🧡💛❤️ #opensource
Firelink Data
Cross-platform Rust library for coloring and formatting terminal output

Coloring terminal output Documentation term-painter is a cross-platform (i.e. also non-ANSI terminals) Rust library for coloring and formatting termin

Lukas Kalbertodt 75 Jul 28, 2022
Vari (Väri) is a Rust library for formatting strings with colors and cosmetic stuff to the terminal.

Vari Vari (Väri) is a Rust library for formatting strings with colors and cosmetic stuff to the terminal. Like Rich library for Python. Väri means "co

azur 13 Nov 2, 2022
create and test the style and formatting of text in your terminal applications

description: create and test the style and formatting of text in your terminal applications docs: https://docs.rs/termstyle termstyle is a library tha

Rett Berg 18 Jul 3, 2021
🍅 A command-line tool to get and set values in toml files while preserving comments and formatting

tomato Get, set, and delete values in TOML files while preserving comments and formatting. That's it. That's the feature set. I wrote tomato to satisf

C J Silverio 15 Dec 23, 2022
Fmt-rfcs - RFCs for Rust formatting guidelines and changes to Rustfmt

Rust code formatting RFCs This repository exists to decide on a code style for Rust code, to be enforced by the Rustfmt tool. Accepted RFCs live in th

null 397 Jan 9, 2023
Monorepo for dprint—a pluggable and configurable code formatting platform

dprint Monorepo for dprint—a pluggable and configurable code formatting platform. This project is under active early development. I recommend you chec

null 1.7k Jan 8, 2023
Sleek is a CLI tool for formatting SQL. It helps you maintain a consistent style across your SQL code, enhancing readability and productivity.

Sleek: SQL Formatter ✨ Sleek is a CLI tool for formatting SQL. It helps you maintain a consistent style across your SQL code, enhancing readability an

Nick Rempel 40 Apr 20, 2023
Fast, minimal, feature-rich, extended formatting syntax for Rust!

Formatting Tools Fast, minimal, feature-rich, extended formatting syntax for Rust! Features include: Arbitrary expressions inside the formatting brace

Casper 58 Dec 26, 2022
Social media style compact number formatting for rust.

prettty-num Format integers into a compact social media style format, similar to using Intl.NumberFormat("en", { notation: "compact" }); as a number f

null 5 Aug 17, 2024
A wayland native, highly customizable runner.

anyrun A wayland native krunner-like runner, made with customizability in mind. Features Style customizability with GTK+ CSS More info in Styling Can

null 18 Jan 22, 2023