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::pipelinemodule 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,
) -> SelfCompare 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 ← allowedBut not from unrelated modules:
crate
├── vulkan
│ └── pipeline ← allowed
│
└── renderer ← NOT allowedWhy use this?
Suppose your project looks like:
src/
└── vulkan/
├── mod.rs
├── pipeline/
│ ├── mod.rs
│ ├── graphics.rs
│ └── shader.rs
└── device.rsYou 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
newvisible 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 namespaceIt’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.