frewsxcv / rust-crates-index

Rust library for retrieving and interacting with the crates.io index
https://docs.rs/crates-index/
Apache License 2.0
72 stars 37 forks source link

Expose `crates_index::git::URL` even without `git` feature #149

Closed Nemo157 closed 1 year ago

Nemo157 commented 1 year ago

I'm transitioning cargo-dl to use the new sparse feature support, as part of that I want to check the .crate download caches for both the sparse and git index to avoid having to actually download if the user has the package already. I'm using crates_index::local_path_and_canonical_url to handle the bulk of the local path determination for me and then moving from that to the cache directory. At least at the moment I don't plan to support using the git index, but to get the URL to pass to local_path... I still need to activate the feature (or hardcode my own copy of it).

Byron commented 1 year ago

Maybe URLs can generally move to their own module which is always available.

Further, I recommend having a look at tame-index, which should provide a better experience around sparse indices while not suffering from #133.

Nemo157 commented 1 year ago

tame-index is actually much less convenient for me, because it returns http::Request instead of http::request::Builder, which ureq doesn't have interop support for, I'd have to manually translate the details. I assume #133 only affects GitIndex so I should be fine with that.

I'm not sure if a module is necessary for the urls, they could be top-level GIT_URL and SPARSE_URL consts, otherwise I guess pub mod urls { const GIT; const SPARSE; } is what you're imagining? I could prepare a PR for whatever you think best.

Byron commented 1 year ago

Maybe none of these is great after all 😅. What about keeping the existing structure and refactor so that git::URL is always available? Then it matches with sparse::URL which is always there as well. And yes, a PR would be appreciated, thanks for offering.