Static visibility/privacy broken since 1.0
Since Version 1.0, statics created using this crate can't be used from other files/modules anymore.
Here's a reproducible example:
src/main.rs
mod statics;
fn main() {
println!("My static: {}", *statics::MY_STATIC);
}
src/statics.rs
use static_init::dynamic;
#[dynamic]
pub static MY_STATIC: u32 = 12;
Running the above code with static_init = "0.5"
works as expected and prints My static: 12
. Compiling it with static_init = "1.0"
fails with this error message:
error[E0446]: private type `__StaticInitGeneratorFor_MY_STATIC` in public interface
--> src/statics.rs:4:1
|
4 | pub static MY_STATIC: u32 = 12;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^--^
| | |
| | `__StaticInitGeneratorFor_MY_STATIC` declared as private
| can't leak private type
error: type `__StaticInitGeneratorFor_MY_STATIC` is private
--> src/main.rs:4:31
|
4 | println!("My static: {}", *statics::MY_STATIC);
| ^^^^^^^^^^^^^^^^^^^ private type
I guess the generated "_StaticInitGenerator..." type should get the same visibility that the original static has.
Rust reference on visibility: https://doc.rust-lang.org/reference/visibility-and-privacy.html