use syn::parse::{Parse, ParseStream};
pub(crate) enum CustomFunction {
Path(syn::Path),
Closure(syn::ExprClosure),
Block(syn::Block),
}
impl Parse for CustomFunction {
fn parse(input: ParseStream) -> syn::Result<Self> {
let closure = if let Ok(path) = input.parse::<syn::Path>() {
Self::Path(path)
} else if let Ok(closure) = input.parse::<syn::ExprClosure>() {
Self::Closure(closure)
} else if let Ok(block) = input.parse::<syn::Block>() {
Self::Block(block)
} else {
return Err(syn::Error::new(
input.span(),
"Invalid `custom` argument input.",
));
};
if !input.peek(syn::Token![,]) && !input.is_empty() {
return Err(input.error("Unexpected token(s)."));
}
Ok(closure)
}
}