-
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: Add auto deserialization of reply data (#445)
- Loading branch information
Showing
8 changed files
with
398 additions
and
8 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,48 @@ | ||
use proc_macro_error::emit_error; | ||
use syn::parse::{Parse, ParseStream, Parser}; | ||
use syn::{Error, Ident, MetaList, Result, Token}; | ||
|
||
/// Type wrapping data parsed from `sv::data` attribute. | ||
#[derive(Default, Debug)] | ||
pub struct DataFieldParams { | ||
pub raw: bool, | ||
pub opt: bool, | ||
} | ||
|
||
impl DataFieldParams { | ||
pub fn new(attr: &MetaList) -> Result<Self> { | ||
DataFieldParams::parse | ||
.parse2(attr.tokens.clone()) | ||
.map_err(|err| { | ||
emit_error!(err.span(), err); | ||
err | ||
}) | ||
} | ||
} | ||
|
||
impl Parse for DataFieldParams { | ||
fn parse(input: ParseStream) -> Result<Self> { | ||
let mut data = Self::default(); | ||
|
||
while !input.is_empty() { | ||
let option: Ident = input.parse()?; | ||
match option.to_string().as_str() { | ||
"raw" => data.raw = true, | ||
"opt" => data.opt = true, | ||
_ => { | ||
return Err(Error::new( | ||
option.span(), | ||
"Invalid data parameter.\n | ||
= note: Expected one of [`raw`, `opt`] comma separated.\n", | ||
)) | ||
} | ||
} | ||
if !input.peek(Token![,]) { | ||
break; | ||
} | ||
let _: Token![,] = input.parse()?; | ||
} | ||
|
||
Ok(data) | ||
} | ||
} |
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.