Skip to main content

Attribute

Struct Attribute 

Source
pub struct Attribute { /* private fields */ }
Expand description

Represents a Rust attribute, tracking its path and attachment style.

Implementations§

Source§

impl Attribute

Source

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());
Source

pub fn with_arguments<I, S>( path: AttributePath, kind: AttributeKind, arguments: I, ) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

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"]);
Source

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"]);
Source

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());
Source

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());
Source

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"]);
Source

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());
Source

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());
Source

pub fn is_test_like_with(&self, additional: &[AttributePath]) -> bool

Indicates whether the attribute marks a test-like context when supplied with additional recognised 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));
Source

pub const fn is_inner(&self) -> bool

Returns true when the attribute is an inner attribute.

§Examples
use whitaker_common::attributes::{Attribute, AttributeKind, AttributePath};

let attribute = Attribute::new(AttributePath::from("doc"), AttributeKind::Inner);
assert!(attribute.is_inner());
Source

pub const fn is_outer(&self) -> bool

Returns true when the attribute is an outer attribute.

§Examples
use whitaker_common::attributes::{Attribute, AttributeKind, AttributePath};

let attribute = Attribute::new(AttributePath::from("doc"), AttributeKind::Outer);
assert!(attribute.is_outer());

Trait Implementations§

Source§

impl Clone for Attribute

Source§

fn clone(&self) -> Attribute

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Attribute

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Attribute

Source§

fn eq(&self, other: &Attribute) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Attribute

Source§

impl StructuralPartialEq for Attribute

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AnyEq for T
where T: Any + PartialEq,

Source§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.