mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-22 05:28:42 +00:00
Refactor: Extract helpers::cratesio_url
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
5ca1278c22
commit
cc13aa911f
2 changed files with 11 additions and 6 deletions
|
@ -10,7 +10,7 @@ use bytes::Bytes;
|
|||
use cargo_toml::Manifest;
|
||||
use futures_util::stream::Stream;
|
||||
use log::debug;
|
||||
use once_cell::sync::OnceCell;
|
||||
use once_cell::sync::{Lazy, OnceCell};
|
||||
use reqwest::{tls, Client, ClientBuilder, Method, Response};
|
||||
use serde::Serialize;
|
||||
use tempfile::NamedTempFile;
|
||||
|
@ -55,6 +55,13 @@ pub fn cargo_home() -> Result<&'static Path, io::Error> {
|
|||
.map(ops::Deref::deref)
|
||||
}
|
||||
|
||||
pub fn cratesio_url() -> &'static Url {
|
||||
static CRATESIO: Lazy<Url, fn() -> Url> =
|
||||
Lazy::new(|| url::Url::parse("https://github.com/rust-lang/crates.io-index").unwrap());
|
||||
|
||||
&*CRATESIO
|
||||
}
|
||||
|
||||
/// Returned file is readable and writable.
|
||||
pub fn create_if_not_exist(path: impl AsRef<Path>) -> io::Result<fs::File> {
|
||||
let path = path.as_ref();
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
use std::{borrow::Cow, fmt, str::FromStr};
|
||||
|
||||
use miette::Diagnostic;
|
||||
use once_cell::sync::Lazy;
|
||||
use semver::Version;
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use thiserror::Error;
|
||||
use url::Url;
|
||||
|
||||
use crate::cratesio_url;
|
||||
|
||||
#[derive(Clone, Debug, Ord, PartialOrd, Eq, PartialEq)]
|
||||
pub struct CrateVersionSource {
|
||||
pub name: String,
|
||||
|
@ -23,10 +24,7 @@ pub enum Source {
|
|||
|
||||
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())
|
||||
Self::Registry(cratesio_url().clone())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue