Skip to content
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

chore: add Borrow impl for Extra and NormalizedPackageName #89

Merged
merged 1 commit into from
Nov 24, 2023

Conversation

baszalmstra
Copy link
Contributor

This allows these types to be used in HashMaps which can be queried by string.

I didnt implement it for PackageName because the hash of PackageName is not equal to the hash of String.

This allows these types to be used in HashMaps which can be queried by
string.
@tdejager tdejager merged commit 2b31e8f into prefix-dev:main Nov 24, 2023
5 checks passed
baszalmstra added a commit to conda/rattler that referenced this pull request Jan 5, 2024
Adds a `Borrow<str>` implementation for `PackageName`.

This allows indexing `HashMap`s with a `PackageName` as key with a
`str`. e.g.:

```rust
fn get_package_version(map: &HashMap<PackageName, Version>) -> Option<&Version> {
    maps.get("normalized_package_name")
}
```

just works.

Previously you would have to write:

```rust
fn get_package_version(map: &HashMap<PackageName, Version>) -> Option<&Version> {
    maps.get(PackageName::from_str("normalized_package_name").unwrap())
}
```

Similar to prefix-dev/rip#89
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants