syn icon indicating copy to clipboard operation
syn copied to clipboard

`TokenMarker` is unexported

Open fredrik-hammar opened this issue 1 year ago • 1 comments

I believe that TokenMarker has been accidentally been left unexported. It's pub while other non-exported items are pub(crate).

pub enum TokenMarker {}

https://github.com/dtolnay/syn/blob/master/src/lookahead.rs#L157

I ran into this when trying to make part of my code more generic, and wanted to map my types to types and items in syn, like this.:

impl InputVariant for MyIdent {
    const TOKEN: fn(syn::lookahead::TokenMarker) -> proc_macro2::Ident = syn::Ident
}

fredrik-hammar avatar Feb 14 '24 18:02 fredrik-hammar

Can you go into more detail what "map my types to types and items in syn" entails? How is the user of the API that you pasted expected to use that API?

dtolnay avatar Feb 14 '24 19:02 dtolnay

For the purpose of making something that can be used from generic code, I think I would prefer to have peek be an associated function, instead of const TOKEN:

impl InputVariant for MyIdent {
    fn peek(input: ParseStream) -> bool {
        input.peek(syn::Ident)
    }
}

dtolnay avatar Mar 11 '24 08:03 dtolnay