Add documentation for name_value_literal_span methods

This commit is contained in:
Guillaume Gomez 2020-12-01 17:32:14 +01:00
parent 63816da5ed
commit a2d1254e22
1 changed files with 14 additions and 0 deletions

View File

@ -180,6 +180,13 @@ impl Attribute {
self.value_str().is_some()
}
/// This is used in case you want the value span instead of the whole attribute. Example:
///
/// ```text
/// #[doc(alias = "foo")]
/// ```
///
/// In here, it'll return a span for `"foo"`.
pub fn name_value_literal_span(&self) -> Option<Span> {
match self.kind {
AttrKind::Normal(ref item, _) => {
@ -241,6 +248,13 @@ impl MetaItem {
self.value_str().is_some()
}
/// This is used in case you want the value span instead of the whole attribute. Example:
///
/// ```text
/// #[doc(alias = "foo")]
/// ```
///
/// In here, it'll return a span for `"foo"`.
pub fn name_value_literal_span(&self) -> Option<Span> {
Some(self.name_value_literal()?.span)
}