Is there a way to use private functions in public macros in Rust?

There is a C function variable that I cannot call outside the macro. This macro is publicly available as it should be, but a C function with variable arguments should not be visible.

Is there a way to make this visible inside the macro? Or maybe a way to save a function outside of documents?

+4
source share
1 answer

The only thing you can do is hide such "internal" characters so that they do not appear in the documentation. For instance:

#[macro_export]
macro_rules! custom_abort {
    ($($args:tt)*) => {
        match format!($($args)*) {
            msg => $crate::custom_abort__(&msg)
        }
    };
}

/// This is an implementation detail and *should not* be called directly!
#[doc(hidden)]
pub fn custom_abort__(msg: &str) -> ! {
    use std::io::Write;
    let _ = writeln!(std::io::stderr(), "{}", msg);
    std::process::exit(1);
}

, - custom_abort__. , - , , .

+5

Source: https://habr.com/ru/post/1629772/


All Articles