Change:
}; } <ins> /// Associated type for `<[char; N] as Pattern<'a>>::Searcher`. #[derive(Clone, Debug)] pub struct CharArraySearcher<'a, const N: usize>( <MultiCharEqPattern<[char; N]> as Pattern<'a>>::Searcher, ); /// Associated type for `<&[char; N] as Pattern<'a>>::Searcher`. #[derive(Clone, Debug)] pub struct CharArrayRefSearcher<'a, 'b, const N: usize>( <MultiCharEqPattern<&'b [char; N]> as Pattern<'a>>::Searcher, ); /// Searches for chars that are equal to any of the [`char`]s in the array. /// /// # Examples /// /// ``` /// assert_eq!("Hello world".find(['l', 'l']), Some(2)); /// assert_eq!("Hello world".find(['l', 'l']), Some(2)); /// ``` impl<'a, const N: usize> Pattern<'a> for [char; N] { pattern_methods!(CharArraySearcher<'a, N>, MultiCharEqPattern, CharArraySearcher); } unsafe impl<'a, const N: usize> Searcher<'a> for CharArraySearcher<'a, N> { searcher_methods!(forward); } unsafe impl<'a, const N: usize> ReverseSearcher<'a> for CharArraySearcher<'a, N> { searcher_methods!(reverse); } /// Searches for chars that are equal to any of the [`char`]s in the array. /// /// # Examples /// /// ``` /// assert_eq!("Hello world".find(&['l', 'l']), Some(2)); /// assert_eq!("Hello world".find(&['l', 'l']), Some(2)); /// ``` impl<'a, 'b, const N: usize> Pattern<'a> for &'b [char; N] { pattern_methods!(CharArrayRefSearcher<'a, 'b, N>, MultiCharEqPattern, CharArrayRefSearcher); } unsafe impl<'a, 'b, const N: usize> Searcher<'a> for CharArrayRefSearcher<'a, 'b, N> { searcher_methods!(forward); } unsafe impl<'a, 'b, const N: usize> ReverseSearcher<'a> for CharArrayRefSearcher<'a, 'b, N> { searcher_methods!(reverse); } </ins> ///////////////////////////////////////////////////////////////////////////// // Impl for &[char] /////////////////////////////////////////////////////////////////////////////

Discussion:
Many methods accept patterns of any type that implements the trait. One such type is , which matches any single character mentioned in the pattern slice. However, patterns are not as nice to use as one might hope. This does not compile: Rust complains: The method constrains its argument type with , and Rust won't apply the usual type coercions like to in order to satisfy trait bounds. One must instead write: It's not a tragedy, but it's not pretty either. CC
Shorter version:
cc
Lovely! This hadn't occurred to me.
Yeah, this was a known issue from the start. This concrete impl is basically a originally-nice API that is old enough that it got gradually worse over time in multiple iterations. If I remember right, there was originally a hardcoded method that just took a , and the language still allowed array literals to coerce to static slices, so originally you could do . At some point we got a cleaning up of the expression syntax, which lead to . And then when I proposed the trait the methods got generic, and no longer liked to do deref coercions, leading to the ugly as shortest possible literal form. I think the only real "fix" for this is deprecating this pattern, and/or holding out till we have char array generics and can have a impl for all directly.
Triage: Seems like the same status today; we are making progress on const generics, but it's not ready yet.