make_public

Macro make_public 

Source
make_public!() { /* proc-macro */ }
Expand description

Recursively makes all top level items in a source public.

Accepts a block of Rust code and makes it so that:

  • Functions become pub fn
  • Structs become pub struct, and all of their fields become public
  • Enums, types, traits (and trait aliases if the unstable feature is enabled), unions, statics, and constants become pub
  • Modules become pub mod and everything underneath them recursively becomes pub
  • impl blocks have all inner items made public (fn, const, type), unless implementing a trait
  • impl-associated types are made pub if the unstable feature is enabled

ยงExample

pub_source::make_public! {
    fn test() {}

    struct Thing {
        field1: u64,
        field2: String,
    }

    impl Thing {
        fn fancy(&self) {
            let _ = self.field1;
        }
    }
}

Expands to:

pub fn test() {}

pub struct Thing {
    pub field1: u64,
    pub field2: String,
}

impl Thing {
    pub fn fancy(&self) {
        let _ = self.field1;
    }
}