local_fmt_macros_internal/util_macro/
arg.rs1use std::str::FromStr;
2
3use proc_macro2::TokenStream;
4use syn::{parse::Parse, LitStr};
5
6use crate::parse::MessageToken;
7
8pub struct Args {
9 pub text: LitStr,
10}
11
12impl Parse for Args {
13 fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
14 Ok(Args {
15 text: input.parse()?,
16 })
17 }
18}
19
20impl Args {
21 pub fn to_token(&self, is_static: bool) -> syn::Result<TokenStream> {
22 let token = MessageToken::from_str(&self.text.value())
23 .map_err(|v| syn::Error::new(self.text.span(), v))?;
24
25 if is_static {
26 Ok(token.to_static_token_stream())
27 } else {
28 Ok(token.to_vec_token_stream())
29 }
30 }
31}