#![doc(test(
no_crate_inject,
attr(
deny(warnings, rust_2018_idioms, single_use_lifetimes),
allow(dead_code, unused_variables)
)
))]
#![forbid(unsafe_code)]
#![warn(future_incompatible, rust_2018_idioms, unreachable_pub)]
#![cfg_attr(test, warn(single_use_lifetimes))]
#![warn(clippy::all, clippy::default_trait_access)]
#![allow(clippy::needless_doctest_main)]
#![allow(clippy::used_underscore_binding, clippy::wildcard_imports)]
#![allow(clippy::wrong_self_convention)] #![cfg_attr(docsrs, feature(doc_cfg))]
#[macro_use]
mod macros;
#[path = "gen/ast_struct.rs"]
mod ast_struct;
#[path = "gen/ast_enum.rs"]
mod ast_enum;
#[path = "gen/convert.rs"]
mod convert;
mod attr {
#[allow(unreachable_pub)] pub use crate::{
ast_enum::{AttrStyle, Meta, NestedMeta},
ast_struct::{Attribute, MetaList, MetaNameValue},
};
}
#[doc(hidden)]
pub use crate::attr::{AttrStyle, Attribute, Meta, MetaList, MetaNameValue, NestedMeta};
mod data;
pub(crate) use crate::data::assert_struct_semi;
#[doc(hidden)]
pub use crate::data::{
Field, Fields, FieldsNamed, FieldsUnnamed, Variant, VisRestricted, Visibility,
};
mod expr;
#[doc(hidden)]
pub use crate::expr::{
Arm, Expr, ExprArray, ExprAssign, ExprAssignOp, ExprAsync, ExprAwait, ExprBinary, ExprBlock,
ExprBox, ExprBreak, ExprCall, ExprCast, ExprClosure, ExprContinue, ExprField, ExprForLoop,
ExprGroup, ExprIf, ExprIndex, ExprLet, ExprLit, ExprLoop, ExprMacro, ExprMatch, ExprMethodCall,
ExprParen, ExprPath, ExprRange, ExprReference, ExprRepeat, ExprReturn, ExprStruct, ExprTry,
ExprTryBlock, ExprTuple, ExprType, ExprUnary, ExprUnsafe, ExprWhile, ExprYield, FieldValue,
GenericMethodArgument, Index, Label, Member, MethodTurbofish, RangeLimits,
};
mod generics;
#[doc(hidden)]
pub use crate::generics::{
BoundLifetimes, ConstParam, GenericParam, Generics, LifetimeDef, PredicateEq,
PredicateLifetime, PredicateType, TraitBound, TraitBoundModifier, TypeParam, TypeParamBound,
WhereClause, WherePredicate,
};
mod item;
#[doc(hidden)]
pub use crate::item::{
FnArg, ForeignItem, ForeignItemFn, ForeignItemMacro, ForeignItemStatic, ForeignItemType,
ImplItem, ImplItemConst, ImplItemMacro, ImplItemMethod, ImplItemType, Item, ItemConst,
ItemEnum, ItemExternCrate, ItemFn, ItemForeignMod, ItemImpl, ItemMacro, ItemMacro2, ItemMod,
ItemStatic, ItemStruct, ItemTrait, ItemTraitAlias, ItemType, ItemUnion, ItemUse, Receiver,
Signature, TraitItem, TraitItemConst, TraitItemMacro, TraitItemMethod, TraitItemType, UseGroup,
UseName, UsePath, UseRename, UseTree,
};
mod file {
#[allow(unreachable_pub)] pub use crate::ast_struct::File;
}
#[doc(hidden)]
pub use crate::file::File;
mod lifetime {
#[allow(unreachable_pub)] pub use crate::ast_struct::Lifetime;
}
#[doc(hidden)]
pub use crate::lifetime::Lifetime;
mod lit;
#[doc(hidden)]
pub use crate::lit::{
Lit, LitBool, LitByte, LitByteStr, LitChar, LitFloat, LitInt, LitStr, StrStyle,
};
mod mac {
#[allow(unreachable_pub)] pub use crate::{ast_enum::MacroDelimiter, ast_struct::Macro};
}
#[doc(hidden)]
pub use crate::mac::{Macro, MacroDelimiter};
mod op {
#[allow(unreachable_pub)] pub use crate::ast_enum::{BinOp, UnOp};
}
#[doc(hidden)]
pub use crate::op::{BinOp, UnOp};
mod ty;
#[doc(hidden)]
pub use crate::ty::{
Abi, BareFnArg, ReturnType, Type, TypeArray, TypeBareFn, TypeGroup, TypeImplTrait, TypeMacro,
TypeParen, TypePath, TypePtr, TypeReference, TypeSlice, TypeTraitObject, TypeTuple, Variadic,
};
mod pat;
#[doc(hidden)]
pub use crate::pat::{
FieldPat, Pat, PatBox, PatIdent, PatLit, PatMacro, PatOr, PatPath, PatRange, PatReference,
PatRest, PatSlice, PatStruct, PatTuple, PatTupleStruct, PatType, PatWild,
};
mod path;
#[doc(hidden)]
pub use crate::path::{
AngleBracketedGenericArguments, Binding, Constraint, GenericArgument,
ParenthesizedGenericArguments, Path, PathArguments, PathSegment, QSelf,
};
mod stmt {
#[allow(unreachable_pub)] pub use crate::{
ast_enum::Stmt,
ast_struct::{Block, Local},
};
}
#[doc(hidden)]
pub use crate::stmt::{Block, Local, Stmt};
mod token_stream;
#[doc(hidden)]
pub use crate::token_stream::{
Delimiter, Group, Ident, Literal, Punct, Spacing, TokenStream, TokenTree,
};
#[cfg(feature = "json")]
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
pub mod json;
mod private {
pub trait Sealed {}
}
#[allow(single_use_lifetimes)] pub trait Syn: Sized + private::Sealed {
type Adapter: Serialize + for<'de> Deserialize<'de>;
fn to_adapter(&self) -> Self::Adapter;
fn from_adapter(adapter: &Self::Adapter) -> Self;
}
use std::ops;
use proc_macro2::Span;
use serde::{Deserialize, Serialize};
type Punctuated<T> = Vec<T>;
fn default<T>() -> T
where
T: Default,
{
T::default()
}
fn default_or_none<T>(x: bool) -> Option<T>
where
T: Default,
{
if x { Some(T::default()) } else { None }
}
fn not<T>(x: T) -> T::Output
where
T: ops::Not,
{
!x
}
trait RefInto<U>: Sized {
fn ref_into<'a>(&'a self) -> U
where
&'a Self: Into<U>,
{
self.into()
}
}
impl<T, U> RefInto<U> for T {}
trait MapInto<U, M> {
type T;
fn ref_map<'a, F>(&'a self, f: F) -> M
where
Self::T: 'a,
F: FnMut(&'a Self::T) -> U;
fn map_into<'a>(&'a self) -> M
where
Self::T: 'a,
&'a Self::T: Into<U>,
{
self.ref_map(Into::into)
}
}
impl<T, U> MapInto<U, Vec<U>> for Vec<T> {
type T = T;
fn ref_map<'a, F>(&'a self, f: F) -> Vec<U>
where
F: FnMut(&'a Self::T) -> U,
{
self.iter().map(f).collect()
}
}
impl<T, U, P> MapInto<U, syn::punctuated::Punctuated<U, P>> for Vec<T>
where
P: Default,
{
type T = T;
fn ref_map<'a, F>(&'a self, f: F) -> syn::punctuated::Punctuated<U, P>
where
F: FnMut(&'a Self::T) -> U,
{
self.iter().map(f).collect()
}
}
impl<T, U, P> MapInto<U, Vec<U>> for syn::punctuated::Punctuated<T, P>
where
P: Default,
{
type T = T;
fn ref_map<'a, F>(&'a self, f: F) -> Vec<U>
where
F: FnMut(&'a Self::T) -> U,
{
self.iter().map(f).collect()
}
}
impl<T, U> MapInto<U, Option<U>> for Option<T> {
type T = T;
fn ref_map<'a, F>(&'a self, f: F) -> Option<U>
where
F: FnMut(&'a Self::T) -> U,
{
self.as_ref().map(f)
}
}
impl<T, U> MapInto<U, Box<U>> for Box<T> {
type T = T;
fn ref_map<'a, F>(&'a self, mut f: F) -> Box<U>
where
F: FnMut(&'a Self::T) -> U,
{
Box::new(f(&**self))
}
}