-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Borrow trait so UniCase can be used as a hashmap key #22
Comments
For reference: there were issues with the soundness of this previously, it might be worth reinvestigating: #6 |
This works, but soundness is reliant on repr(transparent), which isn't implemented yet. Enums like Encoding also aren't compatible with this strategy.
The approach in #6 still produces the same error. It also looks specific to Cow<>. I'm currently using this instead:
|
Since |
uncased is an ASCII-only case insensitive comparison library like UniCase, but it has better support for being used in a map. Specifically, UniCase does not support the Borrow trait (see seanmonstar/unicase#22), so the type phf::Map<UniCase<&'static str>, _> only supports lookups with static string literals, which has limited usefulness. By contrast, the the equivalent uncased construction phf::Map<&'static Uncased, _> *does* support lookups with non-static strings.
uncased is an ASCII-only case insensitive comparison library like UniCase, but it has better support for being used in a map. Specifically, UniCase does not support the Borrow trait (see seanmonstar/unicase#22), so the type phf::Map<UniCase<&'static str>, _> only supports lookups with static string literals, which has limited usefulness. By contrast, the the equivalent uncased construction phf::Map<&'static Uncased, _> *does* support lookups with non-static strings.
uncased is an ASCII-only case insensitive comparison library like UniCase, but it has better support for being used in a map. Specifically, UniCase does not support the Borrow trait (see seanmonstar/unicase#22), so the type phf::Map<UniCase<&'static str>, _> only supports lookups with static string literals, which has limited usefulness. By contrast, the the equivalent uncased construction phf::Map<&'static Uncased, _> *does* support lookups with non-static strings.
I recently needed this. To work around it, I wrapped enum AnyCase<'a> {
Owned(UniCase<String>),
Borrowed(UniCase<&'a str>),
} This way, I can use the |
Another alternative solution is also |
You are right. That was basically |
What we want is The problem is that In principle I think it might be possible to make some kind of custom fat pointer using the unstable pointer metadata API, but it would involve unsafe and be extremely hairy (and I can't see how to avoid stealing a bit from the length, since where else is that bit going to live?). An alternative would be to have a nonoptimised I may experiment with this. |
uncased is an ASCII-only case insensitive comparison library like UniCase, but it has better support for being used in a map. Specifically, UniCase does not support the Borrow trait (see seanmonstar/unicase#22), so the type phf::Map<UniCase<&'static str>, _> only supports lookups with static string literals, which has limited usefulness. By contrast, the the equivalent uncased construction phf::Map<&'static Uncased, _> *does* support lookups with non-static strings.
uncased is an ASCII-only case insensitive comparison library like UniCase, but it has better support for being used in a map. Specifically, UniCase does not support the Borrow trait (see seanmonstar/unicase#22), so the type phf::Map<UniCase<&'static str>, _> only supports lookups with static string literals, which has limited usefulness. By contrast, the the equivalent uncased construction phf::Map<&'static Uncased, _> *does* support lookups with non-static strings.
uncased is an ASCII-only case insensitive comparison library like UniCase, but it has better support for being used in a map. Specifically, UniCase does not support the Borrow trait (see seanmonstar/unicase#22), so the type phf::Map<UniCase<&'static str>, _> only supports lookups with static string literals, which has limited usefulness. By contrast, the the equivalent uncased construction phf::Map<&'static Uncased, _> *does* support lookups with non-static strings.
HashMap<UniCase<String>,String>::get(UniCase<&str>)
The text was updated successfully, but these errors were encountered: