1mod attrs;
2mod expr;
3mod fn_arg;
4mod generic_param;
5mod ident;
6mod item;
7mod iterator;
8mod meta_list;
9mod path;
10mod punctuated;
11mod ty;
12mod vec;
13mod visibility;
1415pub(crate) mod ide;
1617use prelude::*;
1819pub(crate) mod prelude {
20pub(crate) use proc_macro2::{Span, TokenStream};
21pub(crate) use quote::{format_ident, quote, quote_spanned, ToTokens};
2223/// The `Error` type in in this crate is supposed to act like `anyhow::Error`
24 /// providing a simple way to create and return errors from format strings.
25 ///
26 /// See [`err!()`] and [`bail!()`] macros for creating errors. Right now this
27 /// is just a reexport of [`darling::Error`] because that error already provides
28 /// the anyhow-like error handling experience.
29pub(crate) use darling::Error;
3031pub(crate) type Result<T = (), E = Error> = std::result::Result<T, E>;
3233pub(crate) use super::attrs::AttributeExt;
34pub(crate) use super::expr::ExprExt;
35pub(crate) use super::fn_arg::FnArgExt;
36pub(crate) use super::generic_param::GenericParamExt;
37pub(crate) use super::ident::IdentExt;
38pub(crate) use super::item::ItemExt;
39pub(crate) use super::iterator::{IntoIteratorExt, IteratorExt};
40pub(crate) use super::meta_list::MetaListExt;
41pub(crate) use super::path::PathExt;
42pub(crate) use super::punctuated::PunctuatedExt;
43pub(crate) use super::ty::TypeExt;
44pub(crate) use super::vec::VecExt;
45pub(crate) use super::visibility::VisibilityExt;
46pub(crate) use super::{bail, err};
47}
4849/// Inspired by `anyhow::bail`, but returns a [`Result`] with [`darling::Error`].
50/// It accepts the value that implements [`syn::spanned::Spanned`] to attach the
51/// span to the error.
52#[allow(edition_2024_expr_fragment_specifier)]
53macro_rules! bail {
54 ($spanned:expr, $($tt:tt)*) => {
55return Err($crate::util::err!($spanned, $($tt)*))
56 };
57}
5859/// Inspired by `anyhow::anyhow`, but returns a [`darling::Error`].
60/// It accepts the value that implements [`syn::spanned::Spanned`] to attach the
61/// span to the error.
62#[allow(edition_2024_expr_fragment_specifier)]
63macro_rules! err {
64 ($spanned:expr, $($tt:tt)*) => {
65 ::darling::Error::custom(format_args!($($tt)*)).with_span($spanned)
66 };
67}
6869pub(crate) use {bail, err};