Skip to main content

public

Attribute Macro public 

Source
#[public]
Expand description

Procedural macro to expose a private member function for given cfg tags.

This macro creates a public wrapper function with an underscore prefix that calls the original private function. The wrapper is only compiled when the specified cfg condition is met (e.g., feature flags or test mode).

ยงUsage

use macros::public;

struct MyStruct;

impl MyStruct {
    #[public(feature = "dev")]
    fn private_method(&mut self, x: i32) -> i32 {
        x * 2
    }
}

// Generates:
// #[cfg(feature = "dev")]
// pub fn _private_method(&mut self, x: i32) -> i32 {
//     self.private_method(x)
// }