pub trait Replace<'a> {
// Required methods
fn replace_cow<P: Pattern>(self, from: P, to: &str) -> Cow<'a, str>;
fn replacen_cow<P: Pattern>(
self,
from: P,
to: &str,
count: usize,
) -> Cow<'a, str>;
}Available on crate feature
alloc only.Expand description
To extend str and Cow<str> to have replace_cow and replacen_cow methods.
Required Methods§
Sourcefn replace_cow<P: Pattern>(self, from: P, to: &str) -> Cow<'a, str>
fn replace_cow<P: Pattern>(self, from: P, to: &str) -> Cow<'a, str>
Replaces all matches of a pattern with another string, returning a Cow<str> to avoid allocation when possible.
When the input is borrowed and removing matches only changes the prefix or suffix, the returned value also borrows the remaining substring.
Sourcefn replacen_cow<P: Pattern>(
self,
from: P,
to: &str,
count: usize,
) -> Cow<'a, str>
fn replacen_cow<P: Pattern>( self, from: P, to: &str, count: usize, ) -> Cow<'a, str>
Replaces at most count matches of a pattern with another string, returning a Cow<str> to avoid allocation when possible.
When the input is borrowed and removing matches only changes the prefix or suffix, the returned value also borrows the remaining substring.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".