Use CompactString for field CrateVersionSource::name

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-07-28 23:13:47 +10:00
parent cb4cffd0ab
commit 241b763477
No known key found for this signature in database
GPG key ID: 591C0B03040416D6

View file

@ -1,5 +1,6 @@
use std::{borrow::Cow, fmt, str::FromStr}; use std::{borrow::Cow, fmt, str::FromStr};
use compact_str::CompactString;
use miette::Diagnostic; use miette::Diagnostic;
use semver::Version; use semver::Version;
use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde::{Deserialize, Deserializer, Serialize, Serializer};
@ -10,7 +11,7 @@ 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: CompactString,
pub version: Version, pub version: Version,
pub source: Source, pub source: Source,
} }
@ -18,7 +19,7 @@ pub struct CrateVersionSource {
impl From<&super::binstall_v1::MetaData> for CrateVersionSource { impl From<&super::binstall_v1::MetaData> for CrateVersionSource {
fn from(metadata: &super::binstall_v1::MetaData) -> Self { fn from(metadata: &super::binstall_v1::MetaData) -> Self {
super::CrateVersionSource { super::CrateVersionSource {
name: metadata.name.clone().to_string(), name: metadata.name.clone(),
version: metadata.current_version.clone(), version: metadata.current_version.clone(),
source: Source::from(&metadata.source), source: Source::from(&metadata.source),
} }
@ -75,7 +76,7 @@ impl FromStr for CrateVersionSource {
_ => return Err(CvsParseError::BadSource), _ => return Err(CvsParseError::BadSource),
}; };
Ok(Self { Ok(Self {
name: name.to_string(), name: name.into(),
version, version,
source, source,
}) })