Change:
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.

Discussion:
//! assert_eq!(s.find("you"), Some(4)); //! // char pattern //! assert_eq!(s.find('n'), Some(2)); <ins> //! // array of chars pattern //! assert_eq!(s.find(&['a', 'e', 'i', 'o', 'u']), Some(1)); </ins> //! // slice of chars pattern //! assert_eq!(s.find(&['a', 'e', 'i', 'o', 'u'][..]), Some(1)); //! // closure pattern

/// assert_eq!("abaaa".find('b'), Some(1)); /// assert_eq!("abaaa".find('c'), None); /// <ins> /// // &[char; N] /// assert_eq!("ab".find(&['b', 'a']), Some(0)); /// assert_eq!("abaaa".find(&['a', 'z']), Some(0)); /// assert_eq!("abaaa".find(&['c', 'd']), None); /// </ins> /// // &[char] /// assert_eq!("ab".find(&['b', 'a'][..]), Some(0)); /// assert_eq!("abaaa".find(&['a', 'z'][..]), Some(0));

} } <ins> impl<const N: usize> MultiCharEq for [char; N] { #[inline] fn matches(&mut self, c: char) -> bool { self.iter().any(|&m| m == c) } } impl<const N: usize> MultiCharEq for &[char; N] { #[inline] fn matches(&mut self, c: char) -> bool { self.iter().any(|&m| m == c) } } </ins> impl MultiCharEq for &[char] { #[inline] fn matches(&mut self, c: char) -> bool {

}; } <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] /////////////////////////////////////////////////////////////////////////////