Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
padder
A highly efficient Rust crate for padding data during runtime.
padder is a lightweight Rust crate for padding and formatting data structures at runtime efficiently. It provides fine-grained control over alignment, truncating strategies, padding, and memory allocation - making it ideal for performance-critical applications.
Unlike the builtin format! macro, padder avoids unnecessary repeated heap allocations and lets you
pad and format directly into preallocated buffers.
Fully UTF-8 compatible - padder works seamlessly with any Unicode characters like emojis (๐), Japanese kana/kanji (ใใใซใกใฏ), or other multibyte symbols when operating on String types.
Features
- Pad strings, slices, and vectors with custom alignment and width.
- Zero-cost abstractions via the
SourceandMutableSourcetraits. - Pad directly into buffers for fine-grained heap allocation control.
- Highly extensible to custom types through the provided traits.
Installation
Add to you project with Cargo:
cargo add padder
(available features)
- enable_unsafe
Usage
Immutable padding
use *;
// Padding an immutable string slice.
let s: &str = "radagon";
let padded: String = s.pad;
assert_eq!;
// Padding an immutable vector into a preallocted buffer.
let width: usize = 10;
let vec: = Vecfrom;
let mut buf: = Vecwith_capacity;
vec.pad_to_buf;
assert_eq!;
In-place padding
use *;
// Padding a mutable string in-place.
let mut ms = Stringfrom;
.pad;
assert_eq!;
// We can pad again! This time using the wrapper function `pad_mut`.
pad_mut;
assert_eq!;
// And now we can truncate the string -
// (the symbol has no effect when truncating).
.pad;
assert_eq!;
Examples
Take a look in examples/ to see some short examples of how to use this crate.
To test out any of the examples you can run cargo run -p <example-name>.
Benchmarks
Run cargo bench to compare performance against the builtin format! macro. The benchmarks are organized by source type, feature, and alignment strategy.
To benchmark the enable_unsafe feature to verify that the use of unsafe actually improves performance on your system, run the following:
cargo bench --bench enable_unsafe --features enable_unsafe
License
padder is distributed under the terms of both the MIT License and the Apache License (version 2.0).
See LICENSE-APACHE and LICENSE-MIT for details.