Have an Pattern impl for &[[char; 1]]

Currently we have Pattern for &[char]. Problem with that is that even the ppl who wrote the docs for it misunderstood how to use it, so it's definitely confusing enough that anyone from a novice to an advanced Rust user can get it wrong.

Personally we believe making it &[[char; 1]] instead would solve that problem. This is because ppl are gonna assume the inner arrays are effectively 1-codepoint strings and the outer array/slice is a list of choices, instead of assuming concatenation. Because that's how ppl think. Adjusting the API to how ppl think will prevent mistakes in the future.

Not sure if it's possible to deprecate trait impls yet tho.

If you want to make it harder to get confused, I think the natural approach would be to use a named newtype wrapper (e.g. pub struct CharSet(pub &[char]). With the right name, the meaning of that can be completely clear, while the 1-element-array wrappers could still be confusing.

1 Like

Ideally you'd be able to AB-test trait impls. Unfortunately they still come insta-stable. :‌/

We don't see this being a problem, we only see ppl arguing it's gonna be a problem without anything like it ever having existed in the history of Rust. On the other hand &[char]: Pattern has been an actual problem instead of just hypothetical.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.