1 use proc_macro2
::TokenStream
;
2 use quote
::{TokenStreamExt, ToTokens}
;
4 /// Declares the local variable into which errors will be accumulated.
6 pub struct ErrorDeclaration
{
10 impl ToTokens
for ErrorDeclaration
{
11 fn to_tokens(&self, tokens
: &mut TokenStream
) {
12 tokens
.append_all(quote
! {
13 let mut __errors
= ::darling
::export
::Vec
::new();
18 /// Returns early if attribute or body parsing has caused any errors.
20 pub struct ErrorCheck
<'a
> {
21 location
: Option
<&'a
str>,
25 impl<'a
> ErrorCheck
<'a
> {
26 pub fn with_location(location
: &'a
str) -> Self {
28 location
: Some(location
),
34 impl<'a
> ToTokens
for ErrorCheck
<'a
> {
35 fn to_tokens(&self, tokens
: &mut TokenStream
) {
36 let at_call
= if let Some(ref s
) = self.location
{
42 tokens
.append_all(quote
! {
43 if !__errors
.is_empty() {
44 return ::darling
::export
::Err(::darling
::Error
::multiple(__errors
) #at_call);