telety_macro/
lib.rs

1mod crateify;
2mod find_and_replace;
3mod telety;
4mod try_invoke;
5
6/// Enable telety for an item.  
7/// The first argument must be the path to the current module (e.g. `#[telety(crate::my_mod)]`).  
8///
9/// Optional arguments inlcude:  
10/// * telety_path - Provide a path to the contents of the telety crate.  
11///   `#[telety(crate::my_mod, telety_path = "::renamed_telety")]`  
12///   By default this is `::telety`, but if you have renamed or re-exported the crate you can specify its location here.
13/// * macro_ident - The identifier for the telety-generated macro.  
14///   `#[telety(crate::my_mod, macro_ident = "MyStructImpl")]`  
15///   Normally, telety generates a macro with the same identifier as the item. But items such as impls do not have identifiers,
16///   so you can manually specify one.
17/// * visibility - The visibility to generate macros and aliases at.  
18///   `#[telety(crate::my_mod, visibility = "pub(crate)")]`  
19///   telety uses the visibility of the item by default. If the item has no visibility (such as an impl) or you want a more
20///   restrictive visibility, you can use this argument. The visibility must be equal or more restrictive than the item's visibility.
21#[proc_macro_attribute]
22pub fn telety(
23    attr_arg: proc_macro::TokenStream,
24    item: proc_macro::TokenStream,
25) -> proc_macro::TokenStream {
26    let (Ok(ts) | Err(ts)) =
27        telety::telety_impl(attr_arg.into(), item.into()).map_err(syn::Error::into_compile_error);
28    ts.into()
29}
30
31#[proc_macro]
32pub fn crateify(arg: proc_macro::TokenStream) -> proc_macro::TokenStream {
33    let (Ok(ts) | Err(ts)) = crateify::crateify(arg.into()).map_err(syn::Error::into_compile_error);
34    ts.into()
35}
36
37#[proc_macro]
38pub fn find_and_replace(arg: proc_macro::TokenStream) -> proc_macro::TokenStream {
39    let (Ok(ts) | Err(ts)) =
40        find_and_replace::find_and_replace(arg.into()).map_err(syn::Error::into_compile_error);
41    ts.into()
42}
43
44#[proc_macro]
45pub fn try_invoke(arg: proc_macro::TokenStream) -> proc_macro::TokenStream {
46    let (Ok(ts) | Err(ts)) =
47        try_invoke::try_invoke_impl(arg.into()).map_err(syn::Error::into_compile_error);
48    ts.into()
49}