Help on Macro attribute

#[proc_macro_attribute]
pub fn b(attr: TokenStream, func: TokenStream) -> TokenStream {
    let b = parse_macro_input!(func as ItemFn);
    let fn_name = b.sig.ident;
    let billionaire = b.block;
    let billionaire = quote! {
      mod helper {
        pub fn great(billion: i32) {}
      }
      pub fn #fn_name(){
        helper::great(64)
        #billionaire
      }
    };
    TokenStream::from(billionaire)
}
#[b]
fn i() {}

#[b]
fn ii() {}

the name helper is defined multiple times
helper must be defined only once in the type namespace of this module

You can move mod helper inside fn #fn_name.

possiblity to use from outside

there's a trick to workaround this: give the module the same name as the function.

explanation:

function names exist in the value namespace, module names exists in type namespace, so you can use the same name for both the function and the module:

fn foo() {}
mod foo {}

// bonus: macros have yet another distinct namespace
macro_rules! foo {
    () => {}
}