Skip to content

Commit 21976f8

Browse files
committed
refactor(spec): Allow tracking the kind
1 parent d5d9c35 commit 21976f8

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/cargo/core/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub use self::package_id_spec::PackageIdSpec;
88
pub use self::registry::Registry;
99
pub use self::resolver::{Resolve, ResolveVersion};
1010
pub use self::shell::{Shell, Verbosity};
11-
pub use self::source_id::{GitReference, SourceId};
11+
pub use self::source_id::{GitReference, SourceId, SourceKind};
1212
pub use self::summary::{FeatureMap, FeatureValue, Summary};
1313
pub use self::workspace::{
1414
find_workspace_root, resolve_relative_path, MaybePackage, Workspace, WorkspaceConfig,

src/cargo/core/package_id_spec.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use serde::{de, ser};
77
use url::Url;
88

99
use crate::core::PackageId;
10+
use crate::core::SourceKind;
1011
use crate::util::edit_distance;
1112
use crate::util::errors::CargoResult;
1213
use crate::util::{validate_package_name, IntoUrl};
@@ -26,6 +27,7 @@ pub struct PackageIdSpec {
2627
name: String,
2728
version: Option<PartialVersion>,
2829
url: Option<Url>,
30+
kind: Option<SourceKind>,
2931
}
3032

3133
impl PackageIdSpec {
@@ -78,6 +80,7 @@ impl PackageIdSpec {
7880
name: String::from(name),
7981
version,
8082
url: None,
83+
kind: None,
8184
})
8285
}
8386

@@ -101,6 +104,7 @@ impl PackageIdSpec {
101104
name: String::from(package_id.name().as_str()),
102105
version: Some(package_id.version().clone().into()),
103106
url: Some(package_id.source_id().url().clone()),
107+
kind: None,
104108
}
105109
}
106110

@@ -144,6 +148,7 @@ impl PackageIdSpec {
144148
name,
145149
version,
146150
url: Some(url),
151+
kind: None,
147152
})
148153
}
149154

@@ -216,6 +221,7 @@ impl PackageIdSpec {
216221
name: self.name.clone(),
217222
version: self.version.clone(),
218223
url: None,
224+
kind: None,
219225
},
220226
&mut suggestion,
221227
);
@@ -226,6 +232,7 @@ impl PackageIdSpec {
226232
name: self.name.clone(),
227233
version: None,
228234
url: None,
235+
kind: None,
229236
},
230237
&mut suggestion,
231238
);
@@ -346,6 +353,7 @@ mod tests {
346353
name: String::from("foo"),
347354
version: None,
348355
url: Some(Url::parse("https://crates.io/foo").unwrap()),
356+
kind: None,
349357
},
350358
"https://crates.io/foo",
351359
);
@@ -355,6 +363,7 @@ mod tests {
355363
name: String::from("foo"),
356364
version: Some("1.2.3".parse().unwrap()),
357365
url: Some(Url::parse("https://crates.io/foo").unwrap()),
366+
kind: None,
358367
},
359368
"https://crates.io/foo#1.2.3",
360369
);
@@ -364,6 +373,7 @@ mod tests {
364373
name: String::from("foo"),
365374
version: Some("1.2".parse().unwrap()),
366375
url: Some(Url::parse("https://crates.io/foo").unwrap()),
376+
kind: None,
367377
},
368378
"https://crates.io/foo#1.2",
369379
);
@@ -373,6 +383,7 @@ mod tests {
373383
name: String::from("bar"),
374384
version: Some("1.2.3".parse().unwrap()),
375385
url: Some(Url::parse("https://crates.io/foo").unwrap()),
386+
kind: None,
376387
},
377388
"https://crates.io/foo#[email protected]",
378389
);
@@ -382,6 +393,7 @@ mod tests {
382393
name: String::from("bar"),
383394
version: Some("1.2.3".parse().unwrap()),
384395
url: Some(Url::parse("https://crates.io/foo").unwrap()),
396+
kind: None,
385397
},
386398
"https://crates.io/foo#[email protected]",
387399
);
@@ -391,6 +403,7 @@ mod tests {
391403
name: String::from("bar"),
392404
version: Some("1.2".parse().unwrap()),
393405
url: Some(Url::parse("https://crates.io/foo").unwrap()),
406+
kind: None,
394407
},
395408
"https://crates.io/foo#[email protected]",
396409
);
@@ -400,6 +413,7 @@ mod tests {
400413
name: String::from("foo"),
401414
version: None,
402415
url: None,
416+
kind: None,
403417
},
404418
"foo",
405419
);
@@ -409,6 +423,7 @@ mod tests {
409423
name: String::from("foo"),
410424
version: Some("1.2.3".parse().unwrap()),
411425
url: None,
426+
kind: None,
412427
},
413428
414429
);
@@ -418,6 +433,7 @@ mod tests {
418433
name: String::from("foo"),
419434
version: Some("1.2.3".parse().unwrap()),
420435
url: None,
436+
kind: None,
421437
},
422438
423439
);
@@ -427,6 +443,7 @@ mod tests {
427443
name: String::from("foo"),
428444
version: Some("1.2".parse().unwrap()),
429445
url: None,
446+
kind: None,
430447
},
431448
432449
);
@@ -438,6 +455,7 @@ mod tests {
438455
name: String::from("regex"),
439456
version: None,
440457
url: None,
458+
kind: None,
441459
},
442460
"regex",
443461
);
@@ -447,6 +465,7 @@ mod tests {
447465
name: String::from("regex"),
448466
version: Some("1.4".parse().unwrap()),
449467
url: None,
468+
kind: None,
450469
},
451470
452471
);
@@ -456,6 +475,7 @@ mod tests {
456475
name: String::from("regex"),
457476
version: Some("1.4.3".parse().unwrap()),
458477
url: None,
478+
kind: None,
459479
},
460480
461481
);
@@ -465,6 +485,7 @@ mod tests {
465485
name: String::from("regex"),
466486
version: None,
467487
url: Some(Url::parse("https://github.com/rust-lang/crates.io-index").unwrap()),
488+
kind: None,
468489
},
469490
"https://github.com/rust-lang/crates.io-index#regex",
470491
);
@@ -474,6 +495,7 @@ mod tests {
474495
name: String::from("regex"),
475496
version: Some("1.4.3".parse().unwrap()),
476497
url: Some(Url::parse("https://github.com/rust-lang/crates.io-index").unwrap()),
498+
kind: None,
477499
},
478500
"https://github.com/rust-lang/crates.io-index#[email protected]",
479501
);
@@ -483,6 +505,7 @@ mod tests {
483505
name: String::from("cargo"),
484506
version: Some("0.52.0".parse().unwrap()),
485507
url: Some(Url::parse("https://github.com/rust-lang/cargo").unwrap()),
508+
kind: None,
486509
},
487510
"https://github.com/rust-lang/cargo#0.52.0",
488511
);
@@ -492,6 +515,7 @@ mod tests {
492515
name: String::from("cargo-platform"),
493516
version: Some("0.1.2".parse().unwrap()),
494517
url: Some(Url::parse("https://github.com/rust-lang/cargo").unwrap()),
518+
kind: None,
495519
},
496520
"https://github.com/rust-lang/cargo#[email protected]",
497521
);
@@ -501,6 +525,7 @@ mod tests {
501525
name: String::from("regex"),
502526
version: Some("1.4.3".parse().unwrap()),
503527
url: Some(Url::parse("ssh://[email protected]/rust-lang/regex.git").unwrap()),
528+
kind: None,
504529
},
505530
"ssh://[email protected]/rust-lang/regex.git#[email protected]",
506531
);
@@ -510,6 +535,7 @@ mod tests {
510535
name: String::from("foo"),
511536
version: None,
512537
url: Some(Url::parse("file:///path/to/my/project/foo").unwrap()),
538+
kind: None,
513539
},
514540
"file:///path/to/my/project/foo",
515541
);
@@ -519,6 +545,7 @@ mod tests {
519545
name: String::from("foo"),
520546
version: Some("1.1.8".parse().unwrap()),
521547
url: Some(Url::parse("file:///path/to/my/project/foo").unwrap()),
548+
kind: None,
522549
},
523550
"file:///path/to/my/project/foo#1.1.8",
524551
);

src/cargo/core/source_id.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl fmt::Display for Precise {
8585
/// The possible kinds of code source.
8686
/// Along with [`SourceIdInner`], this fully defines the source.
8787
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
88-
enum SourceKind {
88+
pub enum SourceKind {
8989
/// A git repository.
9090
Git(GitReference),
9191
/// A local path.

0 commit comments

Comments
 (0)