224 words
1 minutes
pub_crate_access_mod

link#


pub로 비공개 or 공개용 범위 조절로 내 맘대로 통제하기#

pub(in crate::vulkan::pipeline) is a restricted visibility modifier in Rust.

It means:

This item is public, but only within the crate::vulkan::pipeline module and its descendants.

Your code:

pub(in crate::vulkan::pipeline) unsafe fn new(
    context: &DeviceBundle,
    swapchain: &SwapchainBundle,
    shader_module: vk::ShaderModule,
    vertex_entry: &str,
    fragment_entry: &str,
) -> Self

Compare the visibility modifiers#

pub fn new(...)

Accessible everywhere the containing type is accessible.

pub(crate) fn new(...)

Accessible anywhere inside the current crate.

pub(super) fn new(...)

Accessible from the parent module and its descendants.

pub(in crate::vulkan::pipeline) fn new(...)

Accessible only from:

crate
└── vulkan
    └── pipeline   ← allowed
        ├── ...
        └── children ← allowed

But not from unrelated modules:

crate
├── vulkan
│   └── pipeline   ← allowed

└── renderer       ← NOT allowed

Why use this?#

Suppose your project looks like:

src/
└── vulkan/
    ├── mod.rs
    ├── pipeline/
    │   ├── mod.rs
    │   ├── graphics.rs
    │   └── shader.rs
    └── device.rs

You might want Pipeline::new() to be available to the various pipeline implementation modules, but not to the entire crate.

So:

pub(in crate::vulkan::pipeline) unsafe fn new(...)

essentially says:

“Make new visible to my pipeline subsystem, but don’t expose it to the rest of the crate.”

This is useful for encapsulation.

A useful way to remember it#

Think of:

pub(in crate::vulkan::pipeline)

as:

pub, but only inside this module namespace

It’s more restrictive than:

pub(crate)

because pub(crate) opens access to the entire crate, while pub(in ...) opens it only to a specific module subtree.

pub_crate_access_mod
https://younghakim7.github.io/blog/posts/pub_crate_access_mod/
Author
YoungHa
Published at
2025-12-20