External Publication
Visit Post

Pre-RFC: `pub(api)` visibility, and static enforcement of crate-internal API boundaries

Rust Internals [Unofficial] April 24, 2026
Source

I'm sure this has been discussed before. It would be cool to add an even more general and powerful feature instead.

vis api = vis!(in crate::resources);
vis anotherapi = vis!(in crate::resources);

pub(api) fn foo() {}
pub(anotherapi) fn bar() {}

This would completely solve the problem of

If we later decide to move the file_api module to a different location, we would have to update all of the visibility modifiers

And, I feel this gives developers a simpler model of visibility than needing to understand mod and #[api]. Adding another attribute #[api] doesn't feel like the most elegant solution here.

Granted, we are adding another keyword vis (bikeshedding allowed). And, we will need a syntax for vis!(). But, if we call my pre-pre-pre RFC idea here 'Vis Assignments', then it seems that Vis Assignments solve the same problems presented here but better. Happy to discuss. Vis Assignments would actually be pretty neat.

Discussion in the ATmosphere

Loading comments...