mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-07 20:50:03 +00:00
Refactor: Impl Source::cratesio_registry
Makes initializing `metafiles::CrateVersionSource` more readable and improves performance since the parsing is now cached. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
3961dbb84a
commit
5bdffd9178
2 changed files with 11 additions and 3 deletions
|
@ -650,9 +650,7 @@ async fn install_from_package(
|
|||
let cvs = metafiles::CrateVersionSource {
|
||||
name: name.clone(),
|
||||
version: package.version.parse().into_diagnostic()?,
|
||||
source: metafiles::Source::Registry(
|
||||
url::Url::parse("https://github.com/rust-lang/crates.io-index").unwrap(),
|
||||
),
|
||||
source: metafiles::Source::cratesio_registry(),
|
||||
};
|
||||
|
||||
info!("Installing binaries...");
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use std::{fmt, str::FromStr};
|
||||
|
||||
use miette::Diagnostic;
|
||||
use once_cell::sync::Lazy;
|
||||
use semver::Version;
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use thiserror::Error;
|
||||
|
@ -20,6 +21,15 @@ pub enum Source {
|
|||
Registry(Url),
|
||||
}
|
||||
|
||||
impl Source {
|
||||
pub fn cratesio_registry() -> Source {
|
||||
static CRATESIO: Lazy<Url, fn() -> Url> =
|
||||
Lazy::new(|| url::Url::parse("https://github.com/rust-lang/crates.io-index").unwrap());
|
||||
|
||||
Self::Registry(CRATESIO.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for CrateVersionSource {
|
||||
type Err = CvsParseError;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue