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.

TrimSlice

This trait adds the following basic trimming capabilities to &[u8], Vec<u8>, and Box<[u8]>, similar to those enjoyed by strings.

MethodDescription
trimTrim leading and trailing (ASCII) whitespace.
trim_startTrim leading (ASCII) whitespace.
trim_endTrim trailing (ASCII) whitespace.

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 via callback.
trim_start_matchesTrim arbitrary leading bytes via callback.
trim_end_matchesTrim arbitrary trailing bytes via callback.

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 via callback (mutably).
trim_start_matches_mutTrim arbitrary leading bytes via callback (mutably).
trim_end_matches_mutTrim arbitrary trailing bytes via callback (mutably).

NormalizeWhitespace

This trait exposes an iterator over byte/string slice contents that trims the edges and compacts/converts all inner, contiguous spans of whitespace to a single horizontal space.

This trait is implemented for &[u8], &str, and Iterators with u8/char items.

MethodDescription
normalized_whitespaceReturn a whitespace-normalizing iterator.
normalized_control_and_whitespaceReturn a control- and whitespace-normalizing iterator.

Traits