Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/project-model/src/cargo_workspace.rs')
-rw-r--r--crates/project-model/src/cargo_workspace.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/crates/project-model/src/cargo_workspace.rs b/crates/project-model/src/cargo_workspace.rs
index 617c4116a6..6a932d21f7 100644
--- a/crates/project-model/src/cargo_workspace.rs
+++ b/crates/project-model/src/cargo_workspace.rs
@@ -226,6 +226,7 @@ pub enum TargetKind {
Example,
Test,
Bench,
+ /// Cargo calls this kind `custom-build`
BuildScript,
Other,
}
@@ -254,6 +255,22 @@ impl TargetKind {
pub fn is_proc_macro(self) -> bool {
matches!(self, TargetKind::Lib { is_proc_macro: true })
}
+
+ /// If this is a valid cargo target, returns the name cargo uses in command line arguments
+ /// and output, otherwise None.
+ /// https://docs.rs/cargo_metadata/latest/cargo_metadata/enum.TargetKind.html
+ pub fn as_cargo_target(self) -> Option<&'static str> {
+ match self {
+ TargetKind::Bin => Some("bin"),
+ TargetKind::Lib { is_proc_macro: true } => Some("proc-macro"),
+ TargetKind::Lib { is_proc_macro: false } => Some("lib"),
+ TargetKind::Example => Some("example"),
+ TargetKind::Test => Some("test"),
+ TargetKind::Bench => Some("bench"),
+ TargetKind::BuildScript => Some("custom-build"),
+ TargetKind::Other => None,
+ }
+ }
}
#[derive(Default, Clone, Debug, PartialEq, Eq)]