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