Skip to content

Use Project as a generic bound and move data to constants - #136

Draft
DanielEScherzer wants to merge 10 commits into
rust-lang:mainfrom
DanielEScherzer:generic-project
Draft

Use Project as a generic bound and move data to constants#136
DanielEScherzer wants to merge 10 commits into
rust-lang:mainfrom
DanielEScherzer:generic-project

Conversation

@DanielEScherzer

Copy link
Copy Markdown
Contributor

No description provided.

The parts of `Project` that need to hold different logic for different
projects, and the parts of `Project` that need to be dyn compatible, are
currently both held in the `Project` trait. Introduce a `ProjectDisplayConfig`
struct to hold the parts that need to be dyn compatible and use it in
`ProjectData`.
Rather than using boxed dyn-compatible values, use generics, in preparation for
using associated constants in the `Project` trait.
Switch the `name()`, `url_path()`, `is_homepage()`, and `is_versionless()`
functions to associated constants `NAME`, `URL_PATH`, `IS_HOMEPAGE`, and
`IS_VERSIONLESS` respectively.
Use it to fetch the Oid of the last commit to a specific revision specification
in a git repository.
Now that version logic is part of the `Project` trait and thus specific to a
project, no need to use fancy detection logic.
To simplify adding new ones in the future
@DanielEScherzer

Copy link
Copy Markdown
Contributor Author

CC @Kobzol
This is still a work in progress, but the idea is that it will make adding new projects much easier, e.g. everything that would have been needed to add crates.io is

pub struct CratesIo;

impl Project for CratesIo {
    const NAME: &'static str = "crates.io";
    const URL_PATH: &'static str = "crates.io";
    const IS_VERSIONLESS: bool = true;
    const REPO_URL: &'static str = "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/rust-lang/crates.io.git";

    fn get_versions(repo: &Repository) -> Result<Vec<VersionTag>, Box<dyn std::error::Error>> {
        Ok(vec![VersionTag {
            name: String::from("Nightly"),
            version: Version::new(1, 0, 0),
            raw_tag: String::from("main"),
            commit: revision_latest_commit(repo, "HEAD"),
            in_progress: true,
        }])
    }
}

and then the addition to main()

"crates.io" => CratesIo,

@Kobzol

Kobzol commented Sep 2, 2026

Copy link
Copy Markdown
Member

Could you maybe share some motivation for why you want to do this? Pretty much everything here seems more complicated to me, and I don't see any benefits.

@DanielEScherzer

Copy link
Copy Markdown
Contributor Author

Could you maybe share some motivation for why you want to do this? Pretty much everything here seems more complicated to me, and I don't see any benefits.

I didn't have a chance to review #125 or I would have said something then
I think it is confusing to have getter methods that can be constants

Some of this is useful on its own, #135 and #137

I also don't think this is more complicated, though maybe that is just me

@Kobzol

Kobzol commented Sep 2, 2026

Copy link
Copy Markdown
Member

So I was thinking that we could load some of the simpler, versionless projects from a TOML file (or a set of TOML files), so that we don't need to provide a new trait impl and modify code when adding a new project. Then the function would be needed (I'd just change the str ref to String).

@DanielEScherzer

DanielEScherzer commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

so that we don't need to provide a new trait impl and modify code when adding a new project

I figured that moving things to constants like this PR will do makes the new trait impls much simpler

Then the function would be needed (I'd just change the str ref to String).

which function is this?

Or do you mean that the various getter functions would be needed because the data wouldn't be known at compile time?

@Kobzol

Kobzol commented Sep 2, 2026

Copy link
Copy Markdown
Member

Or do you mean that the various getter functions would be needed because the data wouldn't be known at compile time?

Yeah.

Also I think that in general functions + dyn are the simpler solution here, there's no real need for generics IMO.

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