|0.1.2||Feb 17, 2020|
|0.1.1||Feb 16, 2020|
|0.1.0||Feb 16, 2020|
#778 in Text processing
11,916 downloads per month
Used in 38 crates (10 directly)
Copy-on-write string utils for Rust
perform destructive transformations and so they allocate, copy into and
return a new
when no modification is necessary.
This crate provides a helper trait
CowUtils with drop-in variants of
such methods, which behave in the same way, but avoid extra copies and
allocations when no modification is necessary.
For now it's only implemented for
&str and returns
but in the future might be extended to other types where even more
efficient handling is possible (e.g. in-place modifications on mutable
The primary motivation for this crate was ability to perform zero-alloc replacements when no match is found, so showing results only for
.cow_replace for now.
The actual results will vary depending on the inputs, but here is a taster based on
"a".repeat(40) as an input and various modes (nothing matched, everything matched and replaced, everything matched from the start and deleted):
|params||.replace (ns)||.cow_replace (ns)||difference (%)|
First, you need to import
CowUtils into the scope:
Then you can start invoking following
.cow_-prefixed methods on
strings instead of the regular ones:
Check out the docs for detailed examples.