mut-str
A toolkit for working with mutable string slices (&mut str
), and immutable ones too!
Pretty much all you can do safely in the standard library with mutable string slices is make them lower or upper case. This package allows for splitting and slicing by character index (rather than byte index), replacing strings and using references to characters.
All functions on string slices are available either at the package root or as methods on the StrExt
trait.
Example
use StrExt;
let mut welcome = Box:: from;
// Split by character index
let = welcome.char_split_at_mut.unwrap;
assert_eq!;
assert_eq!;
// Replace string slices
l.replace_with.unwrap;
assert_eq!;
// Replace with padding
let sub = r.replace_with_pad_left_char.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
// Get character references
let crown = welcome.get_char_mut.unwrap;
assert_eq!;
// Mutate characters
crown.replace.unwrap;
assert_eq!;
// Slice by character index
let l = welcome.char_slice_mut.unwrap;
l.replace_with_pad_left_space.unwrap;
assert_eq!;
Links
mut-str
on crates.io
mut-str
on GitHub
Features
alloc
(enabled by default) adds implementations that require thealloc
library.std
(enabled by default, requiresalloc
) adds implementations specific to the standard library.
To make this package no-std
compatible, disable the std
feature.
License
mut-str
is dual-licensed under either the Apache License Version 2.0 or MIT license at your option.