Trait macro_magic_core::ForeignPath

source ·
pub trait ForeignPath {
    // Required method
    fn foreign_path(&self) -> &Path;
}
Expand description

Should be implemented by structs that will be passed to #[with_custom_parsing(..)]. Such structs should also implement syn::parse::Parse.

§Example

#[derive(derive_syn_parse::Parse)]
struct CustomParsingA {
    foreign_path: syn::Path,
    _comma: syn::token::Comma,
    custom_path: syn::Path,
}

impl ToTokens for CustomParsingA {
    fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
        tokens.extend(self.foreign_path.to_token_stream());
        tokens.extend(self._comma.to_token_stream());
        tokens.extend(self.custom_path.to_token_stream());
    }
}

impl ForeignPath for CustomParsingA {
    fn foreign_path(&self) -> &syn::Path {
        &self.foreign_path
    }
}

Required Methods§

source

fn foreign_path(&self) -> &Path

Returns the path of the foreign item whose tokens will be imported.

This is used with custom parsing. See ForeignPath for more info.

Implementors§