Skip to content

Commit

Permalink
Fixup Krates API (#52)
Browse files Browse the repository at this point in the history
* Don't pair name search lifetime to graph lifetime

* Update cfg-expr

* Fix deny

* Update CHANGELOG
  • Loading branch information
Jake-Shadle committed Nov 25, 2022
1 parent 22403eb commit c68becf
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- next-header -->
## [Unreleased] - ReleaseDate
### Changed
- [PR#52](https://github.com/EmbarkStudios/krates/pull/52) updated cfg-expr to 0.12.
- [PR#52](https://github.com/EmbarkStudios/krates/pull/52) changed `Krates::search_matches` and `Krates::search_by_name` to use `impl Into<String>` for the name to search, so that the lifetime of it is not paired with the graph itself.

## [0.12.5] - 2022-11-08
### Fixed
- [PR#51](https://github.com/EmbarkStudios/krates/pull/51) resolved [#50](https://github.com/EmbarkStudios/krates/issues/50) by no longer treating the feature set in the index as authoritative, but rather just merging in the keys that were not already located in the feature set from the crate itself. This would mean that features that are present in both but with different sub-features from the index will now be lost, but that can be fixed later if it is actually an issue.
Expand Down
3 changes: 1 addition & 2 deletions Cargo.toml
Expand Up @@ -22,13 +22,12 @@ default = []
prefer-index = ["crates-index"]
# Adds support for filtering target specific dependencies
targets = ["cfg-expr/targets"]
#features = []

[dependencies]
# Used for acquiring and/or deserializing `cargo metadata` output
cargo_metadata = "0.15"
# Used to parse and evaluate cfg() expressions for dependencies
cfg-expr = "0.11"
cfg-expr = "0.12"
# Allows inspection of the cargo registry index(ices)
crates-index = { version = "0.18", optional = true, default-features = false, features = [
"parallel",
Expand Down
4 changes: 4 additions & 0 deletions deny.toml
Expand Up @@ -16,6 +16,10 @@ copyleft = "deny"

[bans]
multiple-versions = "deny"
skip = [
# Doesn't matter
{ name = "hermit-abi" },
]

[sources]
unknown-registry = "deny"
Expand Down
30 changes: 20 additions & 10 deletions src/lib.rs
Expand Up @@ -455,13 +455,24 @@ where
/// }
/// }
/// ```
pub fn search_matches<'k>(
&'k self,
name: &'k str,
pub fn search_matches(
&self,
name: impl Into<String>,
req: semver::VersionReq,
) -> impl Iterator<Item = (NodeId, &'k N)> + 'k {
self.krates_by_name(name)
.filter(move |(_, n)| req.matches(n.version()))
) -> impl Iterator<Item = (NodeId, &N)> {
let raw_nodes = &self.graph.raw_nodes()[0..self.krates_end];

let name = name.into();

raw_nodes.iter().enumerate().filter_map(move |(id, node)| {
if let Node::Krate { krate, .. } = &node.weight {
if krate.name() == name && req.matches(krate.version()) {
return Some((NodeId::new(id), krate));
}
}

None
})
}

/// Get an iterator over all of the crates in the graph with the given name,
Expand All @@ -476,12 +487,11 @@ where
/// }
/// }
/// ```
pub fn krates_by_name<'k>(
&'k self,
name: &'k str,
) -> impl Iterator<Item = (NodeId, &'k N)> + 'k {
pub fn krates_by_name(&self, name: impl Into<String>) -> impl Iterator<Item = (NodeId, &N)> {
let raw_nodes = &self.graph.raw_nodes()[0..self.krates_end];

let name = name.into();

raw_nodes.iter().enumerate().filter_map(move |(id, node)| {
if let Node::Krate { krate, .. } = &node.weight {
if krate.name() == name {
Expand Down

0 comments on commit c68becf

Please sign in to comment.