-
-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(macros): clean up declare_oxc_secret (#5937)
- Loading branch information
Showing
3 changed files
with
69 additions
and
42 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
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,34 @@ | ||
use syn::{parse::ParseStream, Result, Token}; | ||
|
||
/// Checks if `cond` is `true`, returning [`Err(syn::Error)`] with `msg` if it's not. | ||
/// ## Example | ||
/// ```ignore | ||
/// use syn::{parse::Parse, LitStr}; | ||
/// | ||
/// struct Foo(LitStr); | ||
/// | ||
/// impl Parse for Foo { | ||
/// fn parse(input: ParseStream) -> Result<Self> { | ||
/// let s = input.parse::<LitStr>()?; | ||
/// parse_assert!(s.value() == "foo", s, "Expected 'foo'"); | ||
/// Ok(Foo(s)) | ||
/// } | ||
/// } | ||
/// ``` | ||
macro_rules! parse_assert { | ||
($cond:expr, $toks:expr, $msg:expr) => { | ||
if !($cond) { | ||
return Err(syn::Error::new_spanned($toks, $msg)); | ||
} | ||
}; | ||
} | ||
pub(crate) use parse_assert; | ||
|
||
/// Consume a comma token if it's present, noop otherwise | ||
#[allow(clippy::trivially_copy_pass_by_ref)] | ||
pub(crate) fn eat_comma(input: &ParseStream) -> Result<()> { | ||
if input.peek(Token!(,)) { | ||
input.parse::<Token!(,)>()?; | ||
} | ||
Ok(()) | ||
} |