Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: add Cow guarantee to replace API #1178

Merged
merged 1 commit into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/regex/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,9 @@ impl Regex {
/// case, this implementation will likely return a `Cow::Borrowed` value
/// such that no allocation is performed.
///
/// When a `Cow::Borrowed` is returned, the value returned is guaranteed
/// to be equivalent to the `haystack` given.
///
/// # Replacement string syntax
///
/// All instances of `$ref` in the replacement string are replaced with
Expand Down Expand Up @@ -761,6 +764,13 @@ impl Regex {
/// replacement provided. This is the same as calling `replacen` with
/// `limit` set to `0`.
///
/// If no match is found, then the haystack is returned unchanged. In that
/// case, this implementation will likely return a `Cow::Borrowed` value
/// such that no allocation is performed.
///
/// When a `Cow::Borrowed` is returned, the value returned is guaranteed
/// to be equivalent to the `haystack` given.
///
/// The documentation for [`Regex::replace`] goes into more detail about
/// what kinds of replacement strings are supported.
///
Expand Down Expand Up @@ -855,6 +865,13 @@ impl Regex {
/// matches are replaced. That is, `Regex::replace_all(hay, rep)` is
/// equivalent to `Regex::replacen(hay, 0, rep)`.
///
/// If no match is found, then the haystack is returned unchanged. In that
/// case, this implementation will likely return a `Cow::Borrowed` value
/// such that no allocation is performed.
///
/// When a `Cow::Borrowed` is returned, the value returned is guaranteed
/// to be equivalent to the `haystack` given.
///
/// The documentation for [`Regex::replace`] goes into more detail about
/// what kinds of replacement strings are supported.
///
Expand Down
17 changes: 17 additions & 0 deletions src/regex/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,9 @@ impl Regex {
/// case, this implementation will likely return a `Cow::Borrowed` value
/// such that no allocation is performed.
///
/// When a `Cow::Borrowed` is returned, the value returned is guaranteed
/// to be equivalent to the `haystack` given.
///
/// # Replacement string syntax
///
/// All instances of `$ref` in the replacement string are replaced with
Expand Down Expand Up @@ -748,6 +751,13 @@ impl Regex {
/// replacement provided. This is the same as calling `replacen` with
/// `limit` set to `0`.
///
/// If no match is found, then the haystack is returned unchanged. In that
/// case, this implementation will likely return a `Cow::Borrowed` value
/// such that no allocation is performed.
///
/// When a `Cow::Borrowed` is returned, the value returned is guaranteed
/// to be equivalent to the `haystack` given.
///
/// The documentation for [`Regex::replace`] goes into more detail about
/// what kinds of replacement strings are supported.
///
Expand Down Expand Up @@ -842,6 +852,13 @@ impl Regex {
/// matches are replaced. That is, `Regex::replace_all(hay, rep)` is
/// equivalent to `Regex::replacen(hay, 0, rep)`.
///
/// If no match is found, then the haystack is returned unchanged. In that
/// case, this implementation will likely return a `Cow::Borrowed` value
/// such that no allocation is performed.
///
/// When a `Cow::Borrowed` is returned, the value returned is guaranteed
/// to be equivalent to the `haystack` given.
///
/// The documentation for [`Regex::replace`] goes into more detail about
/// what kinds of replacement strings are supported.
///
Expand Down