-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support omitting data parameter
Expect `(raw)` parameter in the `sv::payload` attribute.
- Loading branch information
Showing
12 changed files
with
262 additions
and
147 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,44 @@ | ||
use proc_macro_error::emit_error; | ||
use syn::parse::{Parse, ParseStream, Parser}; | ||
use syn::{Error, Ident, MetaList, Result}; | ||
|
||
/// Type wrapping data parsed from `sv::payload` attribute. | ||
#[derive(Default, Debug)] | ||
pub struct PayloadFieldParam; | ||
|
||
impl PayloadFieldParam { | ||
pub fn new(attr: &MetaList) -> Result<Self> { | ||
let data = PayloadFieldParam::parse | ||
.parse2(attr.tokens.clone()) | ||
.map_err(|err| { | ||
emit_error!(err.span(), err); | ||
err | ||
})?; | ||
|
||
Ok(data) | ||
} | ||
} | ||
|
||
impl Parse for PayloadFieldParam { | ||
fn parse(input: ParseStream) -> Result<Self> { | ||
let option: Ident = input.parse()?; | ||
match option.to_string().as_str() { | ||
"raw" => (), | ||
_ => { | ||
return Err(Error::new( | ||
option.span(), | ||
"Invalid payload parameter.\n= note: Expected [`raw`].\n", | ||
)) | ||
} | ||
}; | ||
|
||
if !input.is_empty() { | ||
return Err(Error::new( | ||
input.span(), | ||
"Unexpected tokens inside `sv::payload` attribute.\n= note: Expected parameters: [`raw`] `.\n", | ||
)); | ||
} | ||
|
||
Ok(Self) | ||
} | ||
} |
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.