Optimize: Create new fn helpers::cargo_home

that caches return value of `home::cargo_home`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-07-21 13:13:07 +10:00
parent 305a4e4c30
commit 21eac33e1f
No known key found for this signature in database
GPG key ID: 591C0B03040416D6
3 changed files with 14 additions and 2 deletions

View file

@ -1,12 +1,14 @@
use std::fmt::Debug;
use std::fs;
use std::io;
use std::ops;
use std::path::{Path, PathBuf};
use bytes::Bytes;
use cargo_toml::Manifest;
use futures_util::stream::Stream;
use log::debug;
use once_cell::sync::OnceCell;
use reqwest::{tls, Client, ClientBuilder, Method, Response};
use serde::Serialize;
use tempfile::NamedTempFile;
@ -40,6 +42,14 @@ pub use tls_version::TLSVersion;
mod crate_name;
pub use crate_name::CrateName;
pub fn cargo_home() -> Result<&'static Path, io::Error> {
static CARGO_HOME: OnceCell<PathBuf> = OnceCell::new();
CARGO_HOME
.get_or_try_init(home::cargo_home)
.map(ops::Deref::deref)
}
pub async fn await_task<T>(task: tokio::task::JoinHandle<miette::Result<T>>) -> miette::Result<T> {
match task.await {
Ok(res) => res,