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

Changed some load_rustdoc arguments to a struct #347

Merged
merged 4 commits into from
Feb 5, 2023

Conversation

tonowak
Copy link
Collaborator

@tonowak tonowak commented Feb 4, 2023

This PR is a continuation of #341 and #340.

It doesn't yet introduce functional changes -- the only change is that I've defined some new enums/structs and I'm passing them to load_rustdoc functions, instead of several arguments.

The reasoning is that some arguments were not obvious / should have been documented, but it's hard to do it near each load_rustdoc function. It's also convenient to group those struct fields together -- they are strictly related and independent of other load_rustdoc arguments. The new enum allows to execute the new rustdoc generation through the placeholder for the current crate (which will be done in a next PR). The struct also allows for an easier additive change in some next PR, which will add the possibility of choosing which features to enable.

Comment on lines -36 to +37
Self::Registry { crate_ } => crate_.features().keys().cloned().into_iter().collect(),
Self::ManifestPath { manifest } => manifest
.parsed
.features
.keys()
.cloned()
.into_iter()
.collect(),
Self::Registry { crate_ } => crate_.features().keys().cloned().collect(),
Self::ManifestPath { manifest } => manifest.parsed.features.keys().cloned().collect(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was made, because the new clippy complains.

Comment on lines +196 to +204
impl<'a> ToString for CrateType<'a> {
fn to_string(&self) -> String {
match self {
CrateType::Current => "current",
CrateType::Baseline { .. } => "baseline",
}
.to_string()
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels wasteful to create a String when it could be &'static str -- is there a way to do it with this trait, or should I for example remove this trait?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, I merged out of order. In #348 I made this a regular method returning &'static str since we don't actually care about ToString as a trait by itself (we'll never write impl ToString and mean this type).

src/baseline.rs Outdated
Comment on lines 180 to 194
pub(crate) enum CrateType<'a> {
Current,
Baseline {
/// When the baseline is being generated from registry
/// and no specific version was chosen, we want to select a version
/// that is the same or older than the version of the current crate.
highest_allowed_version: Option<&'a semver::Version>,
},
}

pub(crate) struct CrateDataForRustdoc<'a> {
pub(crate) crate_type: CrateType<'a>,
pub(crate) name: &'a str,
// TODO: pass an enum describing which features to enable
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether I like all the names here -- do you have some better ideas @obi1kenobi ?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're ... okay. I don't love them either but none of my ideas are substantially better, and we need this feature much more than we need fancy names here. These will do for now.

@obi1kenobi
Copy link
Owner

Accidentally merged out of order, so these changes got merged in #348.

@obi1kenobi obi1kenobi closed this Feb 5, 2023
@obi1kenobi obi1kenobi reopened this Feb 5, 2023
@obi1kenobi obi1kenobi closed this Feb 5, 2023
@obi1kenobi obi1kenobi reopened this Feb 5, 2023
Copy link
Owner

@obi1kenobi obi1kenobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I managed to stop #348 from merging out of order, so let's do this properly 😅

@obi1kenobi obi1kenobi enabled auto-merge (squash) February 5, 2023 03:23
@obi1kenobi obi1kenobi merged commit 0a4cdef into obi1kenobi:main Feb 5, 2023
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