Add documentation on ast::Attribute
This commit is contained in:
parent
096277e989
commit
33009601af
@ -136,6 +136,13 @@ pub fn is_word(&self) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a list of meta items if the attribute is delimited with parenthesis:
|
||||
///
|
||||
/// ```text
|
||||
/// #[attr(a, b = "c")] // Returns `Some()`.
|
||||
/// #[attr = ""] // Returns `None`.
|
||||
/// #[attr] // Returns `None`.
|
||||
/// ```
|
||||
pub fn meta_item_list(&self) -> Option<ThinVec<MetaItemInner>> {
|
||||
match &self.kind {
|
||||
AttrKind::Normal(normal) => normal.item.meta_item_list(),
|
||||
@ -143,6 +150,21 @@ pub fn meta_item_list(&self) -> Option<ThinVec<MetaItemInner>> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the string value in:
|
||||
///
|
||||
/// ```text
|
||||
/// #[attribute = "value"]
|
||||
/// ^^^^^^^
|
||||
/// ```
|
||||
///
|
||||
/// It returns `None` in any other cases, including doc comments if they
|
||||
/// are not under the form `#[doc = "..."]`.
|
||||
///
|
||||
/// It also returns `None` for:
|
||||
///
|
||||
/// ```text
|
||||
/// #[attr("value")]
|
||||
/// ```
|
||||
pub fn value_str(&self) -> Option<Symbol> {
|
||||
match &self.kind {
|
||||
AttrKind::Normal(normal) => normal.item.value_str(),
|
||||
@ -232,6 +254,18 @@ pub fn meta_item_list(&self) -> Option<ThinVec<MetaItemInner>> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the string value in:
|
||||
///
|
||||
/// ```text
|
||||
/// #[attribute = "value"]
|
||||
/// ^^^^^^^
|
||||
/// ```
|
||||
///
|
||||
/// It returns `None` in any other cases like:
|
||||
///
|
||||
/// ```text
|
||||
/// #[attr("value")]
|
||||
/// ```
|
||||
fn value_str(&self) -> Option<Symbol> {
|
||||
match &self.args {
|
||||
AttrArgs::Eq(_, args) => args.value_str(),
|
||||
@ -315,6 +349,18 @@ pub fn name_value_literal_span(&self) -> Option<Span> {
|
||||
Some(self.name_value_literal()?.span)
|
||||
}
|
||||
|
||||
/// Returns the string value in:
|
||||
///
|
||||
/// ```text
|
||||
/// #[attribute = "value"]
|
||||
/// ^^^^^^^
|
||||
/// ```
|
||||
///
|
||||
/// It returns `None` in any other cases like:
|
||||
///
|
||||
/// ```text
|
||||
/// #[attr("value")]
|
||||
/// ```
|
||||
pub fn value_str(&self) -> Option<Symbol> {
|
||||
match &self.kind {
|
||||
MetaItemKind::NameValue(v) => v.kind.str(),
|
||||
|
Loading…
Reference in New Issue
Block a user