mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-22 21:48:42 +00:00
Use CompactString
for fields of CrateName
Since most of the time, they are shorter than 24 bytes. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
caeb49ce33
commit
d430c077d4
2 changed files with 8 additions and 6 deletions
|
@ -4,6 +4,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use cargo_toml::{Package, Product};
|
use cargo_toml::{Package, Product};
|
||||||
|
use compact_str::CompactString;
|
||||||
use log::{debug, error, info, warn};
|
use log::{debug, error, info, warn};
|
||||||
use miette::{miette, Result};
|
use miette::{miette, Result};
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
|
@ -19,7 +20,7 @@ pub enum Resolution {
|
||||||
Fetch {
|
Fetch {
|
||||||
fetcher: Arc<dyn Fetcher>,
|
fetcher: Arc<dyn Fetcher>,
|
||||||
package: Package<Meta>,
|
package: Package<Meta>,
|
||||||
name: String,
|
name: CompactString,
|
||||||
version: String,
|
version: String,
|
||||||
bin_path: PathBuf,
|
bin_path: PathBuf,
|
||||||
bin_files: Vec<bins::BinFile>,
|
bin_files: Vec<bins::BinFile>,
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
use std::{convert::Infallible, fmt, str::FromStr};
|
use std::{convert::Infallible, fmt, str::FromStr};
|
||||||
|
|
||||||
|
use compact_str::CompactString;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub struct CrateName {
|
pub struct CrateName {
|
||||||
pub name: String,
|
pub name: CompactString,
|
||||||
pub version: Option<String>,
|
pub version: Option<CompactString>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for CrateName {
|
impl fmt::Display for CrateName {
|
||||||
|
@ -26,12 +27,12 @@ impl FromStr for CrateName {
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
Ok(if let Some((name, version)) = s.split_once('@') {
|
Ok(if let Some((name, version)) = s.split_once('@') {
|
||||||
CrateName {
|
CrateName {
|
||||||
name: name.to_string(),
|
name: name.into(),
|
||||||
version: Some(version.to_string()),
|
version: Some(version.into()),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
CrateName {
|
CrateName {
|
||||||
name: s.to_string(),
|
name: s.into(),
|
||||||
version: None,
|
version: None,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue