Pre-1.0 (
0.x). While the crate is at version 0, how the helpers are split into modules — and therefore into Cargo features — may change between releases, and the code-quality and security checks will keep improving. Do not use it in production for critical or sensitive applications until 1.0, which waits for independent security audits. Pin the exact version and read the changelog before upgrading.
Overview
helpers4 is a collection of small, typed helpers for the everyday code every project ends up
rewriting: string casing, slice operations, expiring caches, dates, URLs, versions, hex, network checks, and more. Each
helper does one thing, returns a typed error instead of panicking, and ships with tests and a
runnable example.
Modules
One module per category, each behind a Cargo feature of the same name (all enabled by default):
| Module | What it covers |
|---|---|
ansi |
stripping and building ANSI escape sequences (colors, styles) |
array |
unique, difference, intersection, grouping, counting, duplicates, interleaving |
bytes |
integers at an offset, byte search, XOR, constant-time comparison, 1.5 KiB sizes |
cache |
maps and sets whose entries expire, with the clock passed in |
ci |
which CI service is this, is it a pull request, and a Markdown status report |
color |
#rgb/rgb()/names, HSL, blending and WCAG contrast |
commit |
Conventional Commits: parsing, breaking changes and the version bump they call for |
date |
calendar dates without time zones: ISO 8601, weekdays, day arithmetic |
duration |
parsing and formatting durations as 1h30m |
env |
reading and editing .env files as text |
fs |
atomic writes, missing file as None, listing a tree, lexical path checks |
function |
composition, memoization, retrying with backoff, a token-bucket rate limiter |
future |
block_on, join, join_all and friends, with no async runtime |
hex |
hexadecimal encoding and decoding with typed errors |
http |
extracting a bearer token from an Authorization header |
iter |
chunking, one-pass min/max, first duplicate: for any Iterator |
license |
SPDX identifiers and expressions, MIT OR Apache-2.0 checked against a policy |
map |
picking, omitting and transforming the entries of a HashMap |
markdown |
escaping, links, code blocks, quotes, tables and heading anchors |
net |
is this IP address public (an SSRF guard), is this a valid hostname |
number |
interpolation, rounding, mean, median, percentages, gcd and lcm |
secret |
a wrapper that never prints its value, redaction, masking, token detection |
set |
union and intersection of many sets, toggling, sorted output, similarity, power set |
string |
case conversion, slugs, truncation, indentation, whitespace, HTML escaping |
time |
the system clock as unix time, without a silent 0 |
url |
an RFC 3986 parser with reference resolution, percent-encoding, query strings |
validate |
shape checks: email, UUID, slug |
version |
semantic versions, Cargo-style requirements, comparison |
More are planned (random values and identifiers, …): see the roadmap.
Quick start
use hex;
use is_public_ip;
use slugify;
assert_eq!;
assert_eq!;
assert!; // the cloud metadata address
Names can repeat across modules, so always go through the module path
(helpers4::string::capitalize) and never glob-import a module.
Key features
- Zero dependencies by default: a module that needs one gets its own optional feature
- Take only what you use: one Cargo feature per module, so unused modules are not compiled
- Typed errors instead of panics:
unsafeis forbidden, andunwrap,expectandpanic!are denied outside tests - Explicit inputs: the clock and the process environment are parameters, never ambient
- Standard library first: nothing here duplicates what
stdalready offers - Fully tested: 100% coverage of lines, functions and regions, unit tests, property-based tests, doc tests, mutation testing and benchmarks, all enforced or tracked in CI
- AI-ready:
llms.txtdescribes every module, and every example is a doc test
Documentation
Every helper, with its signature, parameters, errors and examples, is on helpers4.dev/rust and on docs.rs.
Development
See AGENTS.md for the layout and rules, and CONTRIBUTING.md for how to add a helper or a module.
Contributing
Contributions are welcome! Please read CONTRIBUTING.md and the organization's Contributing Guide.
- Fork the repository
- Create a feature branch (
git checkout -b feat/amazing-feature) - Commit your changes following Conventional Commits
- Push to the branch and open a Pull Request
To report a vulnerability, see SECURITY.md.
License
Licensed under the GNU Lesser General Public License v3.0 or later: you can freely use it in proprietary or open-source projects.