Because macro_rules! a little dumber than you might expect. For example, it does not import imports when it expands something. Itβs best to think about expanding macros, as basically just dumb copy + paste work.
If you look at any well-written macro that depends on external characters, you will see things like ::std::result::Result instead of Result . This is because a macro writer cannot depend on Result , which means waiting in the context of an extension. So, the first step is to fully qualify the paths.
The second thing you need to know is that each macro extension gets the $crate substitution, which is the path to the box in which the macro was defined. You can use this to access, for example, a DbaxError as $crate::DbaxError .
Finally, you are lucky; given the extension, you can trick a little and just add use elements inside the extension:
#[macro_export] macro_rules! dbax_call_test { ($func: expr) => { { use std::ffi::CString; use $crate::dbax_function; let call_c_func = unsafe { dbax_function(CString::new($func).unwrap().as_ptr(),0) }; // ... } } }
source share