[][src]Function call2_for_syn::call2_allow_incomplete

pub fn call2_allow_incomplete<T, P: FnOnce(ParseStream<'_>) -> T>(
    input: TokenStream,
    parser: P
) -> T

Analogous to syn::parse2 and syn::parse::ParseBuffer::call.

This function ignores an underlying check whether input was fully parsed.

Examples

use call2_for_syn::call2_allow_incomplete;
use quote::quote;
use syn::{Ident, Token};

let (hello, world) = call2_allow_incomplete(quote!(Hello world!), |input| {
    let hello: Ident = input.parse()?;
    let world: Ident = input.parse()?;
    // input.parse::<Token![!]>()?;
    syn::Result::Ok((hello, world))
})?;

assert_eq!(format!("{}", hello), "Hello");
assert_eq!(format!("{}", world), "world");
use call2_for_syn::call2_allow_incomplete;
use quote::quote;
use syn::{Ident, Token};

let (hello, world) = call2_allow_incomplete(quote!(Hello world!), |input| {
    let hello: Ident = input.parse()?;
    let world: Ident = input.parse()?;
    input.parse::<Token![!]>()?;
    syn::Result::Ok((hello, world))
})?;

assert_eq!(format!("{}", hello), "Hello");
assert_eq!(format!("{}", world), "world");