Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add is_lib, is_bin etc to Target #205

Merged
merged 1 commit into from Sep 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 37 additions & 1 deletion src/lib.rs
Expand Up @@ -425,7 +425,7 @@ impl std::fmt::Display for Source {
pub struct Target {
/// Name as given in the `Cargo.toml` or generated from the file name
pub name: String,
/// Kind of target ("bin", "example", "test", "bench", "lib")
/// Kind of target ("bin", "example", "test", "bench", "lib", "custom-build")
pub kind: Vec<String>,
/// Almost the same as `kind`, except when an example is a library instead of an executable.
/// In that case `crate_types` contains things like `rlib` and `dylib` while `kind` is `example`
Expand Down Expand Up @@ -466,6 +466,42 @@ pub struct Target {
pub doc: bool,
}

impl Target {
fn is_kind(&self, name: &str) -> bool {
self.kind.iter().any(|kind| kind == name)
}

/// Return true if this target is of kind "lib".
pub fn is_lib(&self) -> bool {
self.is_kind("lib")
}

/// Return true if this target is of kind "bin".
pub fn is_bin(&self) -> bool {
self.is_kind("bin")
}

/// Return true if this target is of kind "example".
pub fn is_example(&self) -> bool {
self.is_kind("example")
}

/// Return true if this target is of kind "test".
pub fn is_test(&self) -> bool {
self.is_kind("test")
}

/// Return true if this target is of kind "bench".
pub fn is_bench(&self) -> bool {
self.is_kind("bench")
}

/// Return true if this target is of kind "custom-build".
pub fn is_custom_build(&self) -> bool {
self.is_kind("custom-build")
}
}

/// The Rust edition
///
/// As of writing this comment rust editions 2024, 2027 and 2030 are not actually a thing yet but are parsed nonetheless for future proofing.
Expand Down