@@ -115,6 +115,10 @@ impl NestedMetaItem {
115
115
pub fn is_meta_item_list ( & self ) -> bool {
116
116
self . meta_item_list ( ) . is_some ( )
117
117
}
118
+
119
+ pub fn name_value_literal_span ( & self ) -> Option < Span > {
120
+ self . meta_item ( ) ?. name_value_literal_span ( )
121
+ }
118
122
}
119
123
120
124
impl Attribute {
@@ -175,6 +179,22 @@ impl Attribute {
175
179
pub fn is_value_str ( & self ) -> bool {
176
180
self . value_str ( ) . is_some ( )
177
181
}
182
+
183
+ /// This is used in case you want the value span instead of the whole attribute. Example:
184
+ ///
185
+ /// ```text
186
+ /// #[doc(alias = "foo")]
187
+ /// ```
188
+ ///
189
+ /// In here, it'll return a span for `"foo"`.
190
+ pub fn name_value_literal_span ( & self ) -> Option < Span > {
191
+ match self . kind {
192
+ AttrKind :: Normal ( ref item, _) => {
193
+ item. meta ( self . span ) . and_then ( |meta| meta. name_value_literal_span ( ) )
194
+ }
195
+ AttrKind :: DocComment ( ..) => None ,
196
+ }
197
+ }
178
198
}
179
199
180
200
impl MetaItem {
@@ -227,6 +247,17 @@ impl MetaItem {
227
247
pub fn is_value_str ( & self ) -> bool {
228
248
self . value_str ( ) . is_some ( )
229
249
}
250
+
251
+ /// This is used in case you want the value span instead of the whole attribute. Example:
252
+ ///
253
+ /// ```text
254
+ /// #[doc(alias = "foo")]
255
+ /// ```
256
+ ///
257
+ /// In here, it'll return a span for `"foo"`.
258
+ pub fn name_value_literal_span ( & self ) -> Option < Span > {
259
+ Some ( self . name_value_literal ( ) ?. span )
260
+ }
230
261
}
231
262
232
263
impl AttrItem {
0 commit comments