Skip to content

Commit

Permalink
Rollup merge of rust-lang#132113 - LaihoE:pattern_as_utf8_default_imp…
Browse files Browse the repository at this point in the history
…l, r=workingjubilee

Provide a default impl for Pattern::as_utf8_pattern

Newly added ```Pattern::as_utf8_pattern()``` causes needless breakage for crates that implement Pattern. This provides a default implementation instead.
r? `@BurntSushi`
  • Loading branch information
workingjubilee authored Oct 24, 2024
2 parents 1f2f88e + 115a851 commit 5cf142b
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions core/src/str/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ pub trait Pattern: Sized {
}

/// Returns the pattern as utf-8 bytes if possible.
fn as_utf8_pattern(&self) -> Option<Utf8Pattern<'_>>;
fn as_utf8_pattern(&self) -> Option<Utf8Pattern<'_>> {
None
}
}
/// Result of calling [`Pattern::as_utf8_pattern()`].
/// Can be used for inspecting the contents of a [`Pattern`] in cases
Expand Down Expand Up @@ -675,11 +677,6 @@ impl<C: MultiCharEq> Pattern for MultiCharEqPattern<C> {
fn into_searcher(self, haystack: &str) -> MultiCharEqSearcher<'_, C> {
MultiCharEqSearcher { haystack, char_eq: self.0, char_indices: haystack.char_indices() }
}

#[inline]
fn as_utf8_pattern(&self) -> Option<Utf8Pattern<'_>> {
None
}
}

unsafe impl<'a, C: MultiCharEq> Searcher<'a> for MultiCharEqSearcher<'a, C> {
Expand Down Expand Up @@ -770,11 +767,6 @@ macro_rules! pattern_methods {
{
($pmap)(self).strip_suffix_of(haystack)
}

#[inline]
fn as_utf8_pattern(&self) -> Option<Utf8Pattern<'_>> {
None
}
};
}

Expand Down

0 comments on commit 5cf142b

Please sign in to comment.