@@ -136,13 +136,35 @@ impl Attribute {
136
136
}
137
137
}
138
138
139
+ /// Returns a list of meta items if the attribute is delimited with parenthesis:
140
+ ///
141
+ /// ```text
142
+ /// #[attr(a, b = "c")] // Returns `Some()`.
143
+ /// #[attr = ""] // Returns `None`.
144
+ /// #[attr] // Returns `None`.
145
+ /// ```
139
146
pub fn meta_item_list ( & self ) -> Option < ThinVec < MetaItemInner > > {
140
147
match & self . kind {
141
148
AttrKind :: Normal ( normal) => normal. item . meta_item_list ( ) ,
142
149
AttrKind :: DocComment ( ..) => None ,
143
150
}
144
151
}
145
152
153
+ /// Returns the string value in:
154
+ ///
155
+ /// ```text
156
+ /// #[attribute = "value"]
157
+ /// ^^^^^^^
158
+ /// ```
159
+ ///
160
+ /// It returns `None` in any other cases, including doc comments if they
161
+ /// are not under the form `#[doc = "..."]`.
162
+ ///
163
+ /// It also returns `None` for:
164
+ ///
165
+ /// ```text
166
+ /// #[attr("value")]
167
+ /// ```
146
168
pub fn value_str ( & self ) -> Option < Symbol > {
147
169
match & self . kind {
148
170
AttrKind :: Normal ( normal) => normal. item . value_str ( ) ,
@@ -232,6 +254,18 @@ impl AttrItem {
232
254
}
233
255
}
234
256
257
+ /// Returns the string value in:
258
+ ///
259
+ /// ```text
260
+ /// #[attribute = "value"]
261
+ /// ^^^^^^^
262
+ /// ```
263
+ ///
264
+ /// It returns `None` in any other cases like:
265
+ ///
266
+ /// ```text
267
+ /// #[attr("value")]
268
+ /// ```
235
269
fn value_str ( & self ) -> Option < Symbol > {
236
270
match & self . args {
237
271
AttrArgs :: Eq ( _, args) => args. value_str ( ) ,
@@ -315,6 +349,18 @@ impl MetaItem {
315
349
Some ( self . name_value_literal ( ) ?. span )
316
350
}
317
351
352
+ /// Returns the string value in:
353
+ ///
354
+ /// ```text
355
+ /// #[attribute = "value"]
356
+ /// ^^^^^^^
357
+ /// ```
358
+ ///
359
+ /// It returns `None` in any other cases like:
360
+ ///
361
+ /// ```text
362
+ /// #[attr("value")]
363
+ /// ```
318
364
pub fn value_str ( & self ) -> Option < Symbol > {
319
365
match & self . kind {
320
366
MetaItemKind :: NameValue ( v) => v. kind . str ( ) ,
0 commit comments