diff --git a/src/helpers.rs b/src/helpers.rs index 269557fc..7a7e565d 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -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> = + 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) -> io::Result { let path = path.as_ref(); diff --git a/src/metafiles/cvs.rs b/src/metafiles/cvs.rs index b56ab5fc..15121c69 100644 --- a/src/metafiles/cvs.rs +++ b/src/metafiles/cvs.rs @@ -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> = - Lazy::new(|| url::Url::parse("https://github.com/rust-lang/crates.io-index").unwrap()); - - Self::Registry(CRATESIO.clone()) + Self::Registry(cratesio_url().clone()) } }