whitaker_common/attributes/kind.rs
1//! Attribute classification helpers.
2
3/// Describes whether an attribute is written as `#![...]` or `#[...]`.
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5pub enum AttributeKind {
6 /// Inner attributes appear inside an item: `#![...]`.
7 Inner,
8 /// Outer attributes decorate an item from the outside: `#[...]`.
9 Outer,
10}
11
12impl AttributeKind {
13 /// Returns `true` when the attribute is an inner attribute.
14 ///
15 /// # Examples
16 ///
17 /// ```
18 /// use whitaker_common::attributes::AttributeKind;
19 ///
20 /// assert!(AttributeKind::Inner.is_inner());
21 /// assert!(!AttributeKind::Outer.is_inner());
22 /// ```
23 #[must_use]
24 pub const fn is_inner(self) -> bool {
25 matches!(self, Self::Inner)
26 }
27
28 /// Returns `true` when the attribute is an outer attribute.
29 ///
30 /// # Examples
31 ///
32 /// ```
33 /// use whitaker_common::attributes::AttributeKind;
34 ///
35 /// assert!(AttributeKind::Outer.is_outer());
36 /// assert!(!AttributeKind::Inner.is_outer());
37 /// ```
38 #[must_use]
39 pub const fn is_outer(self) -> bool {
40 matches!(self, Self::Outer)
41 }
42}