# Multiple visibility paths

**URL:** <https://internals.rust-lang.org/t/multiple-visibility-paths/21104>\
**Category:** Uncategorized\
**Created:** [July 1, 2024, 2:59am UTC](https://internals.rust-lang.org/t/multiple-visibility-paths/21104 "2024-07-01T02:59:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Migorithm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/migorithm/32/12296_2.png) [@Migorithm](https://internals.rust-lang.org/u/Migorithm)\
**Post date:** [July 1, 2024, 2:59am UTC](https://internals.rust-lang.org/t/multiple-visibility-paths/21104/1 "2024-07-01T02:59:49Z")

</div>

Currently, it's not possible to denote where a certain code is visible when your target path is not just one.

It'd be great if we could something like:

```rust
pub(in crate::{adapters::repositories, services::views}) async fn your_function(){
/// your code here

}

```

---

<div class="post-metadata">

**Author:** ![josh](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/josh/32/5934_2.png) [@josh](https://internals.rust-lang.org/u/josh)\
**Post date:** [July 1, 2024, 3:48am UTC](https://internals.rust-lang.org/t/multiple-visibility-paths/21104/2 "2024-07-01T03:48:21Z")

</div>

This seems like a high-overhead way to maintain very fine-grained boundaries inside one crate. What is the advantage of this over `pub(crate)`?

---

<div class="post-metadata">

**Author:** ![CAD97](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cad97/32/3460_2.png) [@CAD97](https://internals.rust-lang.org/u/CAD97)\
**Post date:** [July 1, 2024, 4:34am UTC](https://internals.rust-lang.org/t/multiple-visibility-paths/21104/3 "2024-07-01T04:34:56Z")

</div>

`pub(in path)` basically shouldn't be used for paths that aren't a parent to the definition path, and last I heard it doesn't even work as you might expect if you do specify a sibling path.

Narrow visibility that jumps across module boundaries like this almost always is an indicator of poorly structured code. Either it's a reasonable helper to be available and it can be `pub(crate)`, even if most modules won't be interested, or it's tightly coupled to local details and should be `pub(self)` (or sometimes `pub(super)` when splitting large modules into submodules for practicality) and kept close to the code that uses it.

Module API is less critical than crate API, but it has mostly the same design considerations. It doesn't make much sense to say other code can see this, but only if it's in this specific other crate/module — either it's okay to use outside of home or it isn't.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [September 29, 2024, 4:35am UTC](https://internals.rust-lang.org/t/multiple-visibility-paths/21104/4 "2024-09-29T04:35:31Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
