rfcs
rfcs copied to clipboard
Conditional visibility: for integration testing purpose.
For integration testing purpose, it might be necessary to expose more API surface than usual. While it might be possible to directly add integration testing related support, it might be easier to add general purpose mechanism for this.
Strawman proposal:
#[cfg_vis(feature = "internals", pub)]
pub(crate) mod internal_api {
#[cfg_vis(feature = "internals", pub)]
pub(crate) fn foo() {
todo!()
}
}
or
pub (crate if cfg!(not(feature = "internals"))) mod internal_api {
pub (crate if cfg!(not(feature = "internals"))) fn foo() {
todo!()
}
}
or even
#[cfg(feature = "internals")]
vis internals = pub;
#[cfg(not(feature = "internals"))]
vis internals = pub(crate);
pub(internals) mod internal_api {
pub(internals) fn foo() {
todo!()
}
}
Related existing macro-based crates.
- https://docs.rs/visibility
- https://docs.rs/cfg-vis
pub (crate if cfg!(not(feature = "internals"))) mod internal_api {
Maybe more natural as
pub(#[cfg(not(feature = "internals"))] crate) mod internal_api
assuming we accept pub() means pub. But you need to copy this huge thing everywhere, unlike the vis alias.
How is this proposal going to interact with #3323?