#macro #cfg

macro cfg-vis

A macro to support #[cfg()] on visibility

3 releases (breaking)

0.3.0 Feb 11, 2023
0.2.2 Feb 11, 2023
0.2.1 Jan 24, 2023
0.2.0 Jan 23, 2023
0.1.0 Jan 11, 2023

#1485 in Procedural macros

Download history 1646/week @ 2025-12-08 2188/week @ 2025-12-15 681/week @ 2025-12-22 475/week @ 2025-12-29 1383/week @ 2026-01-05 1549/week @ 2026-01-12 1786/week @ 2026-01-19 1707/week @ 2026-01-26 1977/week @ 2026-02-02 1853/week @ 2026-02-09 1828/week @ 2026-02-16 2107/week @ 2026-02-23 2278/week @ 2026-03-02 3911/week @ 2026-03-09 1932/week @ 2026-03-16 1763/week @ 2026-03-23

9,979 downloads per month
Used in 6 crates (2 directly)

MIT license

16KB
344 lines

cfg-vis

A macro to support #[cfg()] on visibility.

use cfg_vis::{cfg_vis, cfg_vis_fields};

// default visibility is `pub`, while the target is linux, the visibility is `pub(crate)`.
#[cfg_vis(target_os = "linux", pub(crate))]
pub fn foo() {}

#[cfg_vis_fields]
pub struct Foo {
    #[cfg_vis(test, pub)]
    pub_in_test: i32,
    #[cfg_vis(test)]
    pub prv_in_test: i32,
}

Dependencies

~4MB
~91K SLoC