Skip to content

why are there two different modules for &str and &[u8] searching instead of one generic API? #1075

Answered by BurntSushi
BurntSushi asked this question in Q&A
Discussion options

You must be logged in to vote

This is a good question. The short answer is that I personally find that generics makes APIs more complex, both in terms of understanding and for use. For use is easy to answer: it can negatively impact inference. It's much nicer, for example, to accept an &str instead of an AsRef<[u8]>. For understanding, it's a bit more subtle and reasonable people can disagree. But in my experience, the existence of type parameters requires reasoning through an abstraction instead of reasoning concretely with specific types. For something like the regex crate, I tried hard to optimize for ease of understanding due to how many folks of varying experience levels are likely to use the crate. regex might b…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by BurntSushi
Comment options

You must be logged in to vote
1 reply
@BurntSushi
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants