Crate trimothy

Source
Expand description

§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]>:

MethodDescription
trim_matchesTrim arbitrary leading and trailing bytes.
trim_start_matchesTrim arbitrary leading bytes.
trim_end_matchesTrim 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]>.

MethodDescription
trim_mutTrim leading and trailing whitespace (mutably).
trim_start_mutTrim leading whitespace (mutably).
trim_end_mutTrim trailing whitespace (mutably).

§TrimMatchesMut

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

MethodDescription
trim_matches_mutTrim arbitrary leading and trailing bytes (mutably).
trim_start_matches_mutTrim arbitrary leading bytes (mutably).
trim_end_matches_mutTrim 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.

MethodDescription
trim_and_normalizeTrim, normalize, and return.

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

Traits§

TrimMatchesMut
Mutable Trim (Matches).
TrimMut
Mutable Trim.
TrimNormal
Trim and (Maybe) Normalize Whitespace.
TrimNormalBytes
Trim and (Maybe) Normalize Whitespace: u8 Iterator Adapter.
TrimNormalChars
Trim and (Maybe) Normalize Whitespace: char Iterator Adapter.
TrimSliceMatches
Trim Slice (Matches).