Skip to content

Commit eaf777e

Browse files
committed
refactor: Change RegistryDependency to use Cow for name and features
Signed-off-by: 0xPoe <techregister@pm.me>
1 parent df7d392 commit eaf777e

File tree

1 file changed

+12
-4
lines changed
  • src/cargo/sources/registry/index

1 file changed

+12
-4
lines changed

src/cargo/sources/registry/index/mod.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,13 @@ struct IndexPackageV {
319319
pub struct RegistryDependency<'a> {
320320
/// Name of the dependency. If the dependency is renamed, the original
321321
/// would be stored in [`RegistryDependency::package`].
322-
pub name: InternedString,
322+
pub name: Cow<'a, str>,
323323
/// The SemVer requirement for this dependency.
324324
#[serde(borrow)]
325325
pub req: Cow<'a, str>,
326326
/// Set of features enabled for this dependency.
327327
#[serde(default)]
328-
pub features: Vec<InternedString>,
328+
pub features: Vec<Cow<'a, str>>,
329329
/// Whether or not this is an optional dependency.
330330
#[serde(default)]
331331
pub optional: bool,
@@ -844,9 +844,13 @@ impl<'a> RegistryDependency<'a> {
844844
default
845845
};
846846

847-
let mut dep = Dependency::parse(package.unwrap_or(name), Some(&req), id)?;
847+
let mut dep = Dependency::parse(
848+
package.unwrap_or(InternedString::new(&name)),
849+
Some(&req),
850+
id,
851+
)?;
848852
if package.is_some() {
849-
dep.set_explicit_name_in_toml(name);
853+
dep.set_explicit_name_in_toml(InternedString::new(&name));
850854
}
851855
let kind = match kind.as_deref().unwrap_or("") {
852856
"dev" => DepKind::Development,
@@ -880,6 +884,10 @@ impl<'a> RegistryDependency<'a> {
880884
dep.set_artifact(artifact);
881885
}
882886

887+
let features = features
888+
.iter()
889+
.map(|f| InternedString::new(&f))
890+
.collect::<Vec<_>>();
883891
dep.set_optional(optional)
884892
.set_default_features(default_features)
885893
.set_features(features)

0 commit comments

Comments
 (0)