Struct telety_impl::Command

source ·
pub struct Command { /* private fields */ }
Expand description

Used to invoke the telety-generated macro in a manageable way.

Implementations§

source§

impl Command

source

pub fn apply( &self, macro_path: &Path, needle: impl Into<SingleToken>, haystack: impl ToTokens, args: Option<TokenStream> ) -> ItemMacro

Creates a macro invocation to use this command with the telety-generated macro at macro_path.
The output of the command will be inserted into haystack at each instance of needle. macro_path must point to a valid telety-generated macro, otherwise a compile error will occur.
To support future Commands, args are passed to the command invocation, but they are not currently used.

§Example
#[proc_macro]
pub fn my_public_macro(tokens: TokenStream) -> TokenStream {
    // ...
    let my_needle: TokenTree = format_ident!("__my_needle__").into();
    v1::UNIQUE_IDENT.apply(
        &parse_quote!(crate::MyTeletyObj),
        &my_needle,
        quote! {
            my_crate::my_macro_implementation!(#my_needle);
        },
        None,
    )
}
#[doc(hidden)]
#[proc_macro]
pub fn my_macro_implementation(tokens: TokenStream) -> TokenStream {
    let ident: Ident = parse2(tokens);
    // ...
}
source

pub fn apply_or( &self, macro_path: &Path, needle: impl Into<SingleToken>, haystack: impl ToTokens, args: Option<TokenStream>, macro_fallback: &Path ) -> ItemMacro

Similar to Command::apply, except if macro_path does not include a macro, macro_fallback will be used instead.
Note that macro_path must still be valid path of some sort (i.e. a type or value), otherwise compilation will fail.
Additionally, for name resolution to succeed, macro_path must start with a qualifier (e.g. ::, self::, crate::, …). If you see the error “import resolution is stuck, try simplifying macro imports”, you are probably missing the qualifier.
Finally, the output will be placed inside a block, which means any items defined inside cannot be easily referenced elsewhere. The primary use-case is to create impls.

source

pub fn apply_exported_or_noop( &self, macro_path: &Path, needle: impl Into<SingleToken>, haystack: impl ToTokens, args: Option<TokenStream>, unique_macro_ident: &Ident ) -> Vec<Item>

Similar to Command::apply_or, except haystack is expanded in the current module or block if macro_path is a macro, otherwise, a noop macro is expanded instead. haystack is forwarded through a macro_rules! macro, but $ tokens within haystack will be automatically converted to work within the macro. unique_macro_ident must be an identifier unique to the crate, as the forwarding macro must be #[macro_export].

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.