16 unstable releases (4 breaking)

new 0.5.0 Nov 19, 2024
0.3.1 Sep 5, 2024
0.3.0 Jul 29, 2024
0.2.2 Oct 5, 2023
0.1.3 May 31, 2022

#26 in No standard library

Download history 39/week @ 2024-08-01 12/week @ 2024-08-08 5/week @ 2024-08-15 5/week @ 2024-08-22 10/week @ 2024-08-29 168/week @ 2024-09-05 31/week @ 2024-09-12 39/week @ 2024-09-19 44/week @ 2024-09-26 31/week @ 2024-10-03 11/week @ 2024-10-10 18/week @ 2024-10-17 3/week @ 2024-10-24 26/week @ 2024-10-31 16/week @ 2024-11-07 210/week @ 2024-11-14

256 downloads per month
Used in 5 crates

WTFPL license

60KB
826 lines

Trimothy

docs.rs changelog
crates.io ci deps.rs
license contributions welcome

Trimothy is a small library that expands on the limited String- and slice-trimming capabilities provided by the standard library.

If any of these methods happened to be introduced into stable Rust in the future, they will simply be removed from here.

This crate is #![no_std]-compatible.

TrimSliceMatches

This trait adds the arbitrary, match-based trimming methods to &[u8], Vec<u8>, and Box<[u8]>:

Method Description
trim_matches Trim arbitrary leading and trailing bytes.
trim_start_matches Trim arbitrary leading bytes.
trim_end_matches Trim arbitrary trailing bytes.

Each of these match methods accept either:

  • A single u8;
  • An array or slice of u8;
  • A &BtreeSet<u8>
  • A custom callback with signature Fn(u8) -> bool

TrimMut

This trait brings mutable trimming support to String, Vec<u8>, and Box<[u8]>.

Method Description
trim_mut Trim leading and trailing whitespace (mutably).
trim_start_mut Trim leading whitespace (mutably).
trim_end_mut Trim trailing whitespace (mutably).

TrimMatchesMut

This trait brings mutable match-based trimming String, Vec<u8>, and Box<[u8]>.

Method Description
trim_matches_mut Trim arbitrary leading and trailing bytes (mutably).
trim_start_matches_mut Trim arbitrary leading bytes (mutably).
trim_end_matches_mut Trim arbitrary trailing bytes (mutably).

Each of these match methods accept either:

  • A single T;
  • An array or slice of T;
  • A &BtreeSet<T>
  • A custom callback with signature Fn(T) -> bool

Where T is char for string sources, and u8 for byte sources.

TrimNormal

This trait adds a single trim_and_normalize method to owned and borrowed string and byte slices that trims leading/trailing whitespace, and compacts/normalizes spans of inner whitespace to a single horizontal space.

Method Description
trim_and_normalize Trim, normalize, and return.

The TrimNormalBytes and TrimNormalChars traits can be used to extend this same functionality to arbitrary iterators of u8 and char, respectively.

Installation

The dependency can be added the normal way:

[dependencies]
trimothy = "0.5"

No runtime deps