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

@ -10,6 +10,7 @@ use serde::{Deserialize, Serialize};
use thiserror::Error;
use super::CrateVersionSource;
use crate::cargo_home;
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct CratesToml {
@ -18,7 +19,7 @@ pub struct CratesToml {
impl CratesToml {
pub fn default_path() -> Result<PathBuf, CratesTomlParseError> {
Ok(home::cargo_home()?.join(".crates.toml"))
Ok(cargo_home()?.join(".crates.toml"))
}
pub fn load() -> Result<Self, CratesTomlParseError> {

View file

@ -9,6 +9,7 @@ use serde::{Deserialize, Serialize};
use thiserror::Error;
use super::CrateVersionSource;
use crate::cargo_home;
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct Crates2Json {
@ -39,7 +40,7 @@ pub struct CrateInfo {
impl Crates2Json {
pub fn default_path() -> Result<PathBuf, Crates2JsonParseError> {
Ok(home::cargo_home()?.join(".crates2.json"))
Ok(cargo_home()?.join(".crates2.json"))
}
pub fn load() -> Result<Self, Crates2JsonParseError> {