Skip to content

Commit

Permalink
Add missing Item::as_*() methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Bromeon authored and PoignardAzur committed Feb 22, 2024
1 parent c892292 commit 32ade31
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions src/types_edition.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::parse_utils::{consume_path, tokens_from_slice};
use crate::types::{
Attribute, AttributeValue, Constant, Enum, EnumVariant, EnumVariantValue, Fields, FnQualifiers,
Function, GenericArg, GenericArgList, GenericBound, GenericParam, GenericParamList, GroupSpan,
Impl, InlineGenericArgs, Item, Lifetime, Module, NamedField, Path, Punctuated, Struct, Trait,
TupleField, TypeAlias, TypeExpr, Union, VisMarker, WhereClause, WhereClausePredicate,
Attribute, AttributeValue, Constant, Enum, EnumVariant, EnumVariantValue, ExternBlock,
ExternCrate, Fields, FnQualifiers, Function, GenericArg, GenericArgList, GenericBound,
GenericParam, GenericParamList, GroupSpan, Impl, InlineGenericArgs, Item, Lifetime, Macro,
Module, NamedField, Path, Punctuated, Struct, Trait, TupleField, TypeAlias, TypeExpr, Union,
UseDeclaration, VisMarker, WhereClause, WhereClausePredicate,
};
use proc_macro2::{Group, Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
use quote::spanned::Spanned;
Expand Down Expand Up @@ -183,7 +184,7 @@ impl Item {
}

/// Returns the [`TypeAlias`] variant of the enum if possible.
pub fn as_ty_definition(&self) -> Option<&TypeAlias> {
pub fn as_type_alias(&self) -> Option<&TypeAlias> {
match self {
Item::TypeAlias(ty_decl) => Some(ty_decl),
_ => None,
Expand All @@ -206,6 +207,38 @@ impl Item {
}
}

/// Returns the [`UseDeclaration`] variant of the enum if possible.
pub fn as_use_declaration(&self) -> Option<&UseDeclaration> {
match self {
Item::UseDeclaration(use_decl) => Some(use_decl),
_ => None,
}
}

/// Returns the [`Macro`] variant of the enum if possible.
pub fn as_macro(&self) -> Option<&Macro> {
match self {
Item::Macro(macro_decl) => Some(macro_decl),
_ => None,
}
}

/// Returns the [`ExternBlock`] variant of the enum if possible.
pub fn as_extern_block(&self) -> Option<&ExternBlock> {
match self {
Item::ExternBlock(block_decl) => Some(block_decl),
_ => None,
}
}

/// Returns the [`ExternCrate`] variant of the enum if possible.
pub fn as_extern_crate(&self) -> Option<&ExternCrate> {
match self {
Item::ExternCrate(crate_decl) => Some(crate_decl),
_ => None,
}
}

/// Venial doesn't have an equivalent for the syn split_for_impl() method.
///
/// Given the syn use-case:
Expand Down

0 comments on commit 32ade31

Please sign in to comment.