-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from TedDriggs/errors
Rework errors to support returning multiple at once
- Loading branch information
Showing
17 changed files
with
644 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use quote::{Tokens, ToTokens}; | ||
|
||
/// Declares the local variable into which errors will be accumulated. | ||
pub struct ErrorDeclaration { | ||
__hidden: () | ||
} | ||
|
||
impl ErrorDeclaration { | ||
pub fn new() -> Self { | ||
ErrorDeclaration { | ||
__hidden: () | ||
} | ||
} | ||
} | ||
|
||
impl ToTokens for ErrorDeclaration { | ||
fn to_tokens(&self, tokens: &mut Tokens) { | ||
tokens.append(quote! { | ||
let mut __errors = Vec::new(); | ||
}) | ||
} | ||
} | ||
|
||
/// Returns early if attribute or body parsing has caused any errors. | ||
pub struct ErrorCheck { | ||
__hidden: () | ||
} | ||
|
||
impl ErrorCheck { | ||
pub fn new() -> Self { | ||
ErrorCheck { | ||
__hidden: () | ||
} | ||
} | ||
} | ||
|
||
impl ToTokens for ErrorCheck { | ||
fn to_tokens(&self, tokens: &mut Tokens) { | ||
tokens.append(quote! { | ||
if !__errors.is_empty() { | ||
return ::darling::export::Err(::darling::Error::multiple(__errors)); | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.