Skip to content

Commit

Permalink
Allow feature data to not be loaded. (#651)
Browse files Browse the repository at this point in the history
Don't crash if no features data has been loaded. Instead, return no data
in those cases.
  • Loading branch information
obi1kenobi committed Dec 10, 2024
1 parent f014b5e commit cc20e53
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/adapter/edges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,16 @@ pub(super) fn resolve_crate_edge<'a, V: AsVertex<Vertex<'a>> + 'a>(
resolve_neighbors_with(contexts, move |vertex| {
let origin = vertex.origin;

let features_lookup = match origin {
let Some(features_lookup) = match origin {
Origin::CurrentCrate => &current_crate.features,
Origin::PreviousCrate => {
&previous_crate.expect("no previous crate provided").features
}
}
.as_ref()
.expect("no feature data was loaded");
.as_ref() else {
// No feature data was loaded.
return Box::new(std::iter::empty());
};

Box::new(
features_lookup
Expand All @@ -97,14 +99,16 @@ pub(super) fn resolve_crate_edge<'a, V: AsVertex<Vertex<'a>> + 'a>(
resolve_neighbors_with(contexts, move |vertex| {
let origin = vertex.origin;

let features_lookup = match origin {
let Some(features_lookup) = match origin {
Origin::CurrentCrate => &current_crate.features,
Origin::PreviousCrate => {
&previous_crate.expect("no previous crate provided").features
}
}
.as_ref()
.expect("no feature data was loaded");
.as_ref() else {
// No feature data was loaded.
return Box::new(std::iter::empty());
};

// If there's no `default` feature, then no features are enabled by default.
let Some(default_feature) = features_lookup.features.get("default") else {
Expand Down
4 changes: 4 additions & 0 deletions src/rustdoc_schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type Crate {
We heuristically disregard features prefixed with `_`, and features introduced by
optional dependencies that are never referenced by any other feature.
We deem those features to be non-user-facing, and do not show them here.
If feature data is not loaded into the adapter, this edge will not have any instances.
"""
feature: [Feature!]

Expand All @@ -52,6 +54,8 @@ type Crate {
We heuristically disregard features prefixed with `_`, and features introduced by
optional dependencies that are never referenced by any other feature.
We deem those features to be non-user-facing, and do not show them here.
If feature data is not loaded into the adapter, this edge will not have any instances.
"""
default_feature: [Feature!]
}
Expand Down

0 comments on commit cc20e53

Please sign in to comment.