pub struct Attribute { /* private fields */ }Expand description
Represents a Rust attribute, tracking its path and attachment style.
Implementations§
Source§impl Attribute
impl Attribute
Sourcepub fn new(path: AttributePath, kind: AttributeKind) -> Self
pub fn new(path: AttributePath, kind: AttributeKind) -> Self
Creates a new attribute without arguments.
§Examples
use whitaker_common::attributes::{Attribute, AttributeKind, AttributePath};
let attribute = Attribute::new(AttributePath::from("test"), AttributeKind::Outer);
assert!(attribute.is_outer());Sourcepub fn with_arguments<I, S>(
path: AttributePath,
kind: AttributeKind,
arguments: I,
) -> Self
pub fn with_arguments<I, S>( path: AttributePath, kind: AttributeKind, arguments: I, ) -> Self
Creates an attribute with the provided argument strings.
§Examples
use whitaker_common::attributes::{Attribute, AttributeKind, AttributePath};
let attribute = Attribute::with_arguments(
AttributePath::from("allow"),
AttributeKind::Outer,
["clippy::needless_bool"],
);
assert_eq!(attribute.arguments(), &["clippy::needless_bool"]);Sourcepub fn with_str_arguments(
path: AttributePath,
kind: AttributeKind,
args: &[&str],
) -> Self
pub fn with_str_arguments( path: AttributePath, kind: AttributeKind, args: &[&str], ) -> Self
Creates an attribute with borrowed string arguments.
§Examples
use whitaker_common::attributes::{Attribute, AttributeKind, AttributePath};
let attribute = Attribute::with_str_arguments(
AttributePath::from("allow"),
AttributeKind::Outer,
&["clippy::needless_bool"],
);
assert_eq!(attribute.arguments(), &["clippy::needless_bool"]);Sourcepub fn path(&self) -> &AttributePath
pub fn path(&self) -> &AttributePath
Returns the underlying attribute path.
§Examples
use whitaker_common::attributes::{Attribute, AttributeKind, AttributePath};
let attribute = Attribute::new(AttributePath::from("doc"), AttributeKind::Outer);
assert!(attribute.path().is_doc());Sourcepub const fn kind(&self) -> AttributeKind
pub const fn kind(&self) -> AttributeKind
Returns the attachment kind (inner or outer).
§Examples
use whitaker_common::attributes::{Attribute, AttributeKind, AttributePath};
let attribute = Attribute::new(AttributePath::from("doc"), AttributeKind::Inner);
assert!(attribute.kind().is_inner());Sourcepub fn arguments(&self) -> &[String]
pub fn arguments(&self) -> &[String]
Returns the attribute arguments.
§Examples
use whitaker_common::attributes::{Attribute, AttributeKind, AttributePath};
let attribute = Attribute::with_str_arguments(
AttributePath::from("allow"),
AttributeKind::Outer,
&["dead_code"],
);
assert_eq!(attribute.arguments(), &["dead_code"]);Sourcepub fn is_doc(&self) -> bool
pub fn is_doc(&self) -> bool
Indicates whether the attribute is a doc comment (#[doc = ...]).
§Examples
use whitaker_common::attributes::{Attribute, AttributeKind, AttributePath};
let attribute = Attribute::new(AttributePath::from("doc"), AttributeKind::Outer);
assert!(attribute.is_doc());Sourcepub fn is_test_like(&self) -> bool
pub fn is_test_like(&self) -> bool
Indicates whether the attribute marks a test-like context.
Builtin test-like attributes include direct paths such as test,
tokio::test, async_std::test, and rstest, plus prelude-qualified
builtin forms such as ::core::prelude::v1::test and
::std::prelude::rust_2024::test. The latter are recognized via
matches_builtin_test_like_path on self.path.
§Examples
use whitaker_common::attributes::{Attribute, AttributeKind, AttributePath};
let rstest = Attribute::new(AttributePath::from("rstest"), AttributeKind::Outer);
assert!(rstest.is_test_like());Sourcepub fn is_test_like_with(&self, additional: &[AttributePath]) -> bool
pub fn is_test_like_with(&self, additional: &[AttributePath]) -> bool
Indicates whether the attribute marks a test-like context when supplied with additional recognized paths.
Builtin test-like attributes include direct paths such as test,
tokio::test, async_std::test, and rstest, plus prelude-qualified
builtin forms such as ::core::prelude::v1::test and
::std::prelude::rust_2024::test. These builtin forms are recognized
first by calling matches_builtin_test_like_path on self.path.
Use additional only for extra runtime-configured AttributePath
values that should count as test-like in addition to the builtin set.
§Examples
use whitaker_common::attributes::{Attribute, AttributeKind, AttributePath};
let attr = Attribute::new(AttributePath::from("custom::test"), AttributeKind::Outer);
let additional = vec![AttributePath::from("custom::test")];
assert!(attr.is_test_like_with(&additional));